What error are you getting ?
Oct 25, 2022
11
Level 3
How to use middleware in routes/Api.php ?
Hello, i want to use middleware in api.php, i have Vue inside laravel, and making fetch request from it. My middleware works fine in web.php, but when i add middleware in api.php, i get and errors and can not fetch , i want to use auth middleware (im autorized);
my api . php
Route::get('/check', [Controller::class, 'index'])->middleware('auth')
Level 3
thank everyone for helping, although i found answer by myself (my question was a little bit wrong), i changed my kernel file like this
protected $middlewareGroups = [
'web' => [
some stuff which i not change
],
'api' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
removed everything from my 'api' and added these code, after this it start working
Please or to participate in this conversation.