Laravel - RESTful API

0

I'm following a tutorial, for creating a Rest application in Laravel , in the second part of this tutorial Laravel -parte2 , when I use the command:

php artisan route:list

Displays this error

PHP Fatal error:  Class 'App\Http\Controllers\Controller' not found in C:\xampp\htdocs\laravel-api\app\Http\Controllers\JobsController.php on line 11

[Symfony\Component\Debug\Exception\FatalErrorException]
   Class 'App\Http\Controllers\Controller' not found

My controlller

class JobsController extends Controller{

public function index()
{
    $jobs = Job::with('company')->get();
    return response()->json($jobs);//retornando um tipo json
}


class CompaniesController extends Controller{

public function index()
{
    $companies = Company::all();
    return response()->json($companies);
}

If anyone knows any other tutorial for me to draw too, I'm available.

    
asked by anonymous 20.11.2017 / 04:04

1 answer

0

Somehow Laravel can not find your JobsController , run

composer dump-autoload

Then check the vendor / composer / autoload_classmap.php file, your JobsController should be there, otherwise the composer will not be able to do autoload and Laravel you will not have access to it.

If you can not find your drivers, you should check:

1) Your composer.json file, the folder where your drivers should be:

"autoload": {
    "classmap": [
        "app/controllers",
                  ....
    ],

2) Verify that your classes are named correctly.

3) If you are using a namespace:

The JobsController class extends the Controller {...}

You should use namespace in your references.

4) Compare the classes you have in autoload_classmap.php with those that are not there. There should be a difference in naming or directory placement.

5) Make sure your classes start with

<?php 

and not just

<?

This may not make much of a difference for composer or PHP, but it does for Laravel.

  

Similar Problem

    
20.11.2017 / 11:22