Laravel: Symfony\Component\Routing\Exception\RouteNotFoundException: Route [login] not defined
Code called route('name') for a route name that doesn’t exist — very often route('login') from the auth middleware in API-only apps.
Seen on:
Laravel
Meaning
The auth middleware redirects guests to the route named login. API routes without a login route should return 401 JSON instead (send Accept: application/json, or customise redirectTo). Cached routes (route:cache) can also be stale.
Common causes
- No route named login when auth middleware redirects guests
- Typo in route name or route not named
- Stale route cache after deploy
- API request without Accept: application/json
⚡ Quick fix
- Name the route (->name('login')) or add one
- For APIs send Accept: application/json / customise the guest redirect
- php artisan route:clear (and route:cache again)
Detailed fix by platform
PHP
- php
// bootstrap/app.php (Laravel 11) ->withMiddleware(function (Middleware $m) { $m->redirectGuestsTo(fn ($request) => $request->expectsJson() ? null : route('login')); })
Shell
- php
php artisan route:list --name=login php artisan route:clear
How to diagnose
- Routes — route:list
- Request — Accept header (API)?
- Cache — Route cache stale?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026