Hocam bu şekilde dener misiniz
class RoleMiddleware
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next, string $role): Response
{
if (! auth()->check()) {
return response()->json(['error' => 'Unauthorized', 'message' => 'Please log in'], 401);
}
if (! auth()->user()->roles()->where('name', $role)->exists()) {
return response()->json(['error' => 'Unauthorized', 'message' => 'You do not have the required role.'], 403);
}
return $next($request);
}
}