Laravel 5.5多认证报错:InvalidArgumentException 认证用户提供者未定义
Hey there! Let's break down why you're hitting that InvalidArgumentException at CreatesUserProviders.php line 42, and how to fix it quickly.
The Root Cause
Looking at your config/auth.php guards setup, your admin guard specifies 'provider' => 'adminss'—but Laravel has no idea what adminss is because you haven't defined it in the providers section of the same config file. That's exactly why you're getting this error: the framework can't find the user provider you're referencing.
Step 1: Add the Missing Provider to config/auth.php
Open up config/auth.php and look for the providers array. You need to add an entry for adminss that points to your Admin model. Here's how it should look:
'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => App\User::class, ], // Add this new provider entry 'adminss' => [ 'driver' => 'eloquent', 'model' => App\Admin::class, ], ],
This tells Laravel: "When using the adminss provider, use the Eloquent driver and pull user data from the App\Admin model."
Step 2: Verify Your Admin Model Setup
Make sure your Admin model is properly set up to work with Laravel's authentication. It should extend Authenticatable (which gives it all the core auth methods) and use the Notifiable trait. Here's the complete structure you need:
<?php namespace App; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class Admin extends Authenticatable { use Notifiable; // Optional: If your admins are stored in a table named something other than 'admins', specify it here // protected $table = 'your_admin_table_name'; // Define fillable fields (adjust based on your database schema) protected $fillable = [ 'name', 'email', 'password', ]; // Define hidden fields (usually password and remember_token) protected $hidden = [ 'password', 'remember_token', ]; }
Step 3: Clear Config Cache
Laravel caches config files for performance, so you'll need to clear that cache to make sure your new provider setup takes effect. Run this command in your terminal:
php artisan config:clear
That's it! Your multi-auth setup should now work without throwing that exception.
内容的提问来源于stack exchange,提问作者Sai Krishna

