withRouting( web: __DIR__.'/../routes/web.php', api: __DIR__.'/../routes/api.php', commands: __DIR__.'/../routes/console.php', health: '/up', ) ->withMiddleware(function (Middleware $middleware) { // Let the Next.js admin panel authenticate with a Sanctum session // cookie issued on the same registrable domain, instead of shipping a // bearer token to JavaScript. $middleware->statefulApi(); $middleware->api(prepend: [ AuthenticateAdminPanelSession::class, ]); $middleware->alias([ 'admin' => EnsureUserIsAdmin::class, ]); // This is an API-only application with no `login` route. Without this, // an unauthenticated write request that does not advertise JSON (a // plain form POST or curl) resolves `route('login')` and dies with // "Route [login] not defined" instead of a 401. $middleware->redirectGuestsTo(fn () => null); }) ->withExceptions(function (Exceptions $exceptions) { $exceptions->shouldRenderJsonWhen( fn ($request) => $request->is('api/*') || $request->expectsJson() ); })->create();