0

I'm learning laravel and I've tried to create a Controller. I'm really new, so, please, elaborate.

I've used the following command to create the Controller

php artisan make:controller Api/EstadoController

So, EstadoController is under Controllers/Api

I also created a route at api.php

Route::namespace('API')->name('api.')->group(function() {
  Route::get('/estados', 'EstadoController@index')->name('estados');
});

EstadoController has index function and correct namespace:

<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class EstadoController extends Controller
{
    public function index(){
      return Estado::all();
    }
}

Here is the error page:

enter image description here

Alan Godoi
  • 657
  • 1
  • 12
  • 39

2 Answers2

3

Changing

API

to

Api

in my route resolved, like route creation.

Route:

Route::namespace('Api')->name('api.')->group(function() {
  Route::get('/estados', 'EstadoController@index')->name('estados');
});
Alan Godoi
  • 657
  • 1
  • 12
  • 39
0

Please try to make route like this:

Route::get('/estados', 'Api\EstadoController@index');

PHP Geek
  • 3,949
  • 1
  • 16
  • 32