i have a small crud frontend to store information. The frontend controller is called ShowsController
. And i want to get alle Shows from the api.
So my routes/web.php
contains:
Route::resource('shows', 'ShowsController');
Thats perfect and worked really well.
My routes/api.php
contains:
Route::resource('shows', 'ShowsController', ['only' => ['index']]);
The route /api/shows
should give me the shows as json. to decide frontend and api i put the ShowsController
into Controllers/Api folder
The Controllers/Api/ShowsController
contains:
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Show;
class ShowsController extends Controller
{
public function index(){
return response()
->json(Show::all())->withHeaders([
'Content-Type' => 'text/json',
'Access-Control-Allow-Origin' => '*'
]);
}
}
And i also changed the RouteServiceProvider
to:
protected function mapApiRoutes()
{
Route::group([
'middleware' => 'api',
'namespace' => 'Api',
'prefix' => 'api',
], function ($router) {
require base_path('routes/api.php');
});
}
But the command php artisan route:list
gives me an exception:
[ReflectionException]
Class Api\ShowsController does not exist
Why is laravel not finding the defined ShowsController in the api directory?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2fdgfex
via IFTTT
Aucun commentaire:
Enregistrer un commentaire