laravel/framework · error · InvalidArgumentException
Authentication user provider
Error message
Authentication user provider [{$driver}] is not defined. What it means
Thrown by CreatesUserProviders::createUserProvider() when the provider's 'driver' is neither 'database' nor 'eloquent' and no custom provider creator has been registered via Auth::provider(). User providers are the backends that retrieve user records (Eloquent model, DB query builder, etc.).
Solutions
- Set the provider's driver to 'eloquent' (with a 'model') or 'database' (with a 'table').
- Register the custom provider via Auth::provider('mydriver', fn ($app, $config) => new MyUserProvider(...)) before it is resolved.
- Verify the guard's 'provider' key matches an entry under 'providers' in auth.php.
- Run php artisan config:clear to drop a stale cached config.
Example fix
// before
'providers' => [
'users' => ['driver' => 'mydriver', 'model' => User::class], // not registered
],
// after — register in AuthServiceProvider::boot()
Auth::provider('mydriver', function ($app, array $config) {
return new MyUserProvider($app['hash'], $config['model']);
});
// or switch to a built-in driver:
'providers' => [
'users' => ['driver' => 'eloquent', 'model' => User::class],
], Defensive patterns
Strategy: validation
Validate before calling
// PHP — verify the provider driver before resolving
$providerKey = config('auth.guards.web.provider');
$providerCfg = config("auth.providers.{$providerKey}");
$driver = $providerCfg['driver'] ?? null;
$ok = in_array($driver, ['eloquent','database'], true) || app()->bound("auth.provider.creator.{$driver}");
if (! $ok) abort(500, "User provider driver [{$driver}] is not defined."); Type guard
function providerDriverIsRegistered(?string $driver): bool {
return in_array($driver, ['eloquent','database'], true);
} Try / catch
try {
Auth::createUserProvider($provider);
} catch (\InvalidArgumentException $e) {
report('Unknown user provider driver: '.$e->getMessage());
throw $e;
} Prevention
- Use 'eloquent' or 'database' providers unless a custom one is registered.
- Register custom providers via Auth::provider() before resolution.
- Clear config cache after editing auth.php.
When it happens
Trigger: Configuring a guard's 'provider' to a key whose entry in config/auth.php 'providers' uses an unknown 'driver'; referencing a custom provider driver before calling Auth::provider($driver, $callback).
Common situations: Typo in provider driver ('eloquen'); removing a package that registered a custom user provider; config cache from before a custom provider was registered in a service provider; pointing a guard at a provider that was deleted from auth.php.
Understand the failure class
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
Related errors
- Auth driver [ ] for guard [ ] is not defined.
- Auth guard [ ] is not defined.
- Password resetter [ ] is not defined.
- A driver must be specified.
- Broadcast connection
AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11).
Data as JSON: /api/errors/bea9b9c431f53876.
Report an issue: GitHub.
Appendix: source
Thrown at src/Illuminate/Auth/CreatesUserProviders.php:39
*
* @throws \InvalidArgumentException
*/
public function createUserProvider($provider = null)
{
if (is_null($config = $this->getProviderConfiguration($provider))) {
return;
}
if (isset($this->customProviderCreators[$driver = ($config['driver'] ?? null)])) {
return call_user_func(
$this->customProviderCreators[$driver], $this->app, $config
);
}
return match ($driver) {
'database' => $this->createDatabaseProvider($config),
'eloquent' => $this->createEloquentProvider($config),
default => throw new InvalidArgumentException(
"Authentication user provider [{$driver}] is not defined."
),
};
}
/**
* Get the user provider configuration.
*
* @param string|null $provider
* @return array|null
*/
protected function getProviderConfiguration($provider)
{
if ($provider = $provider ?: $this->getDefaultUserProvider()) {
return $this->app['config']['auth.providers.'.$provider];
}
}
View on GitHub (pinned to e0f6eb3518)