{"id":"976fb1007f4f4439","repo":"laravel/framework","slug":"auth-guard-name-is-not-defined","errorCode":null,"errorMessage":"Auth guard [{$name}] is not defined.","messagePattern":"Auth guard \\[(.+?)\\] is not defined\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Auth/AuthManager.php","lineNumber":90,"sourceCode":"        $name = enum_value($name) ?: $this->getDefaultDriver();\n\n        return $this->guards[$name] ??= $this->resolve($name);\n    }\n\n    /**\n     * Resolve the given guard.\n     *\n     * @param  string  $name\n     * @return \\Illuminate\\Contracts\\Auth\\Guard|\\Illuminate\\Contracts\\Auth\\StatefulGuard\n     *\n     * @throws \\InvalidArgumentException\n     */\n    protected function resolve($name)\n    {\n        $config = $this->getConfig($name);\n\n        if (is_null($config)) {\n            throw new InvalidArgumentException(\"Auth guard [{$name}] is not defined.\");\n        }\n\n        if (isset($this->customCreators[$config['driver']])) {\n            return $this->callCustomCreator($name, $config);\n        }\n\n        $driverMethod = 'create'.ucfirst($config['driver']).'Driver';\n\n        if (method_exists($this, $driverMethod)) {\n            return $this->{$driverMethod}($name, $config);\n        }\n\n        throw new InvalidArgumentException(\n            \"Auth driver [{$config['driver']}] for guard [{$name}] is not defined.\"\n        );\n    }\n\n    /**","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Auth/AuthManager.php#L72-L108","documentation":"Thrown by AuthManager::resolve() when getConfig($name) returns null, i.e. there is no 'auth.guards.{name}' key in config/auth.php. The manager cannot build a guard it has no configuration for.","triggerScenarios":"Calling Auth::guard('admin') when 'admin' is not listed under auth.guards; accessing Auth::user() when auth.defaults.guard points to a guard name that was removed or renamed.","commonSituations":"Renaming a guard but forgetting to update AUTH_GUARD env; typo in the guard name passed to the auth middleware (Route::middleware('auth:admins')); a package that expects a guard you never published.","solutions":["Add the missing guard entry under 'guards' in config/auth.php with a valid 'driver' and 'provider'.","Check the value of auth.defaults.guard and your AUTH_GUARD env variable.","Verify the guard name spelling in middleware: Route::middleware('auth:web').","Run php artisan config:clear after editing config/auth.php."],"exampleFix":"// before - config/auth.php\n'guards' => [\n    'web' => ['driver' => 'session', 'provider' => 'users'],\n],\n// Auth::guard('admin') throws\n\n// after\n'guards' => [\n    'web' => ['driver' => 'session', 'provider' => 'users'],\n    'admin' => ['driver' => 'session', 'provider' => 'admins'],\n],","handlingStrategy":"validation","validationCode":"$guard = 'admin';\nif (is_null(config(\"auth.guards.{$guard}\"))) {\n    throw new RuntimeException(\"Guard [{$guard}] is not configured in auth.guards.\");\n}\nAuth::guard($guard)->user();","typeGuard":"function guardIsConfigured(string $guard): bool\n{\n    return ! is_null(config(\"auth.guards.{$guard}\"));\n}","tryCatchPattern":"try {\n    return Auth::guard($name)->user();\n} catch (\\InvalidArgumentException $e) {\n    // fall back to default guard or abort with a clear config error\n    return Auth::guard()->user();\n}","preventionTips":["Centralize guard name lookups behind a helper that checks config existence first.","Add a boot-time assertion listing all guards referenced by middleware and verifying they exist in config.","Run config:clear after changing auth config so stale cache does not hide missing guards."],"tags":["authentication","configuration","guard","laravel"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}