Route [login] not defined 🔺 Laravel

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

  1. Name the route (->name('login')) or add one
  2. For APIs send Accept: application/json / customise the guest redirect
  3. php artisan route:clear (and route:cache again)

Detailed fix by platform

PHP

  1. php
    // bootstrap/app.php (Laravel 11)
    ->withMiddleware(function (Middleware $m) {
        $m->redirectGuestsTo(fn ($request) => $request->expectsJson() ? null : route('login'));
    })

Shell

  1. php
    php artisan route:list --name=login
    php artisan route:clear

How to diagnose

  1. Routes — route:list
  2. Request — Accept header (API)?
  3. 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.