Laravel - Restful API

Asked

Viewed 104 times

0

I’m following a tutorial, for creating an application Rest in Laravel, in the second part of this tutorial Orange -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

Mine 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 am available.

1 answer

0

Somehow Laravel isn’t finding his Jobscontroller, execute

composer dump-autoload

Then check the vendor/Composer/autoload_classmap.php file, your Jobscontroller should be there, otherwise Poser will not be able to autoload and the Laravel will not have access to it.

If you can’t find your controllers, you should check:

1) Your Composer.json file, the folder where your controllers should be:

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

2) Check that your classes are named correctly.

3) If you are using a namespace:

The class Jobscontroller extend the Controller {...}

You must use the namespace in its references.

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

5) Check if your classes start with

<?php 

and not just

<?

This may not make much difference to Composer or PHP, but it does to Laravel.

Similar problem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.