'Laravel multi auth - Authentication user provider [] is not defined
It works when it put
'merchant' => [
'driver' => 'session',
'provider' => 'users',
],
But It shows error when I set a different table
'merchant' => [
'driver' => 'session',
'provider' => 'merchants',
],
Error: InvalidArgumentException in CreatesUserProviders.php line 40: Authentication user provider [] is not defined.
What is the problem. Would you please explain me ? Thanks.
Solution 1:[1]
At first did you create your merchants providers?
if you didnt
php artisan make:provider MerchantServiceProvider
Then you have to register your provider in: config/app.php/
'providers' => [ App\Providers\RouteServiceProvider::class ]
Solution 2:[2]
If you want to change the register / authentication table go back with your changes, you only need to change in the config/auth.php file
'providers' => [
'users' => [
'driver' => 'eloquent',
/*change this ---->*/ 'model' => App\<modelclassname>::class,
],
This are the Authentication user provider, so if what you want is to add a new provider, you need to add another provider to this array. The error that you have is because the provider mechants that you are calling is not registered here.
And check that your /app/modelname.php has the protected table created like this:
protected $table = 'merchant'; // ----> this is your table name
So if you want to use multiple providers, you should register your provider in the user provider section of the config/auth.php file. Your provider array should look like this:
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Users::class,
],
'merchant' => [
'driver' => 'eloquent',
'model' => App\Merchant::class,
],
],
After that you should able to use the provider as you write in the question.
Solution 3:[3]
You can always use my package https://github.com/Hesto/multi-auth and focus on your application instead of this annoying configuration.
Solution 4:[4]
You may use database or elequent relationship as driver .
'branchs' => [
'driver' => 'database',
'provider' => 'merchants',
],
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Eliott |
Solution 2 | |
Solution 3 | Hesto |
Solution 4 | rashedcs |