Как решить проблемы c регистрацией посредников (Middleware) в Laravel 11 версии?
Проблема с мидлваром а ларке 11 версии.
Есть мидлвар проверки роли админа:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class CheckAdminMiddleware
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if(!Auth()->check() || !Auth()->user()->is_admin){
return response()->json(['message' => '
User is not an administrator.'], 401);
}
return $next($request);
}
}
Регистрирую в kernel.php:
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Auth\Middleware\Authenticate;
use Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful;
use App\Http\Middleware\VerifyCsrfToken;
use App\Http\Middleware\CorsAndHeaderMiddleware;
use App\Http\Middleware\CheckAdminMiddleware;
class Kernel extends HttpKernel
{
protected $middleware = [
CorsAndHeaderMiddleware::class,
VerifyCsrfToken::class,
];
protected $middlewareGroups = [
'api' => [
EnsureFrontendRequestsAreStateful::class,
'throttle:api',
SubstituteBindings::class,
ThrottleRequests::class . ':api',
],
];
protected $routeMiddleware = [
'auth' => Authenticate::class,
'admin' => CheckAdminMiddleware::class
];
}
Как пример сделаю проверку на роль админа при запросе выхода в api.php:
Route::middleware(['auth:sanctum', 'admin'])->group(function () {
Route::post('/logout', [AuthController::class, 'logout']);
});
Постман выводит такую ошибку " message": "Target class [admin] does not exist."
Я наверное уже все перерыл в интернете и решения нету