{"record":{"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/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Auth/AuthManager.php#L72-L108","documentation":"Thrown by AuthManager::resolve() when getConfig($name) returns null — i.e. no guard entry exists in config/auth.php under 'guards' for the requested name. The manager looks up the guard's configuration array before attempting to build a driver, so a missing key is treated as an undefined guard.","triggerScenarios":"Requesting a guard via Auth::guard($name), Auth::shouldUse($name), or via middleware auth:$name where $name is absent from the 'guards' config map; using the default guard when 'defaults.guard' points at a non-existent guard name.","commonSituations":"Renaming/removing a guard in auth.php while middleware/routes still reference the old name; setting AUTH_GUARD env value that is not declared; typo in the route middleware string (e.g. auth:webb); config cache (php artisan config:cache) holding a stale auth.php after edits.","solutions":["Add the guard to config/auth.php under 'guards' with a driver and provider, e.g. 'api' => ['driver' => 'sanctum'|'token'|'session', 'provider' => 'users'].","Correct the route middleware / Auth::guard() name to match an existing guard key.","Set 'defaults.guard' to a guard that actually exists in the 'guards' map.","Clear the config cache: php artisan config:clear, then re-cache if needed.","Verify the AUTH_GUARD environment variable matches a declared guard."],"exampleFix":"// before — middleware references an undeclared guard\nRoute::middleware('auth:portal')->group(...);\n// config/auth.php 'guards' => ['web' => [...], 'api' => [...]]\n\n// after — declare the guard\n// config/auth.php\n'guards' => [\n    'web' => ['driver' => 'session', 'provider' => 'users'],\n    'api' => ['driver' => 'sanctum', 'provider' => 'users'],\n    'portal' => ['driver' => 'session', 'provider' => 'members'],\n],","handlingStrategy":"validation","validationCode":"// PHP — confirm a guard exists before resolving\n$name = $request->route()?->middleware() ? \\Str::between(last(array_filter($request->route()->middleware(), fn($m) => str_starts_with($m,'auth:'))), 'auth:', '') : null;\n$config = config(\"auth.guards.{$name}\");\nif ($name !== null && $config === null) {\n    abort(500, \"Auth guard [{$name}] is not configured.\");\n}\n$guard = Auth::guard($name);","typeGuard":"function guardIsDefined(string $name): bool {\n    return is_array(config(\"auth.guards.{$name}\"));\n}","tryCatchPattern":"try {\n    return Auth::guard($name);\n} catch (\\InvalidArgumentException $e) {\n    Log::error('Unknown auth guard requested', ['guard' => $name]);\n    throw $e;\n}","preventionTips":["Always declare a guard in auth.php before referencing it in middleware.","Set defaults.guard to a guard that exists.","Run php artisan config:clear after editing auth.php."],"tags":["authentication","guard","laravel","configuration"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}