If you build your projects with Filament, you have probably hit this error when a user's session ends, or when you reinstall the database while you still have a session open:
Route [login] not defined.
It shows up without Filament too, as soon as you have built your own authentication page and named the route something other than exactly login — admin.login, for instance.
Why it happens
Laravel's authentication middleware needs somewhere to send a visitor who is not signed in. By default it assumes a route named login exists, and when it cannot find one it throws instead of redirecting.
The fix
On Laravel 11 and later you override that behaviour from bootstrap/app.php:
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware): void {
$middleware->redirectGuestsTo('login');
})
->withExceptions(function (Exceptions $exceptions): void {
//
})->create();
The whole change is the one call inside the withMiddleware callback:
$middleware->redirectGuestsTo('login');
The argument is just the path you want guests sent to. If your Filament panel lives at /admin, that would be admin/login.
It also accepts a closure, which is what you want when the destination depends on the request:
$middleware->redirectGuestsTo(fn () => route('admin.login'));
With that in place, a visitor without a session lands on your sign-in screen instead of an error page.