I am new to laravel.Firstly Api.php was not initially created in routes.After creating this is my code:
<?php
use IlluminateHttpRequest;
use IlluminateSupportFacadesRoute;
use AppHttpControllersApiStudentController;
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
}
);
Route:: get('student',[StudentController::class,'index']);
Route::fallback(function ()
{
return response()->view('errors.404', [], 404);
});
But when I am running php artisan route:list student is not there.If I run it in localhost it is showing 404 not found
Can you help me?
2
Answers
are you using laravel version 11? If yes, please run the
php artisan install:api
command. Ref: https://laravel.com/docs/11.x/routing#api-routesFrom the Laravel 11 changelog:
Run the artisan command below to set it up.
Manually creating the
api.php
file does not actually register the routes. Running the artisan command adds an entry in yourbootstrap/app.php
file: