Hi,
I have 3 user types in my project; customers, business admins and the app admins. I using a multiple authentication system for the project and I would like to leave laravel's default user authentication and User model for customer authentication. I am using voyager for the app admins authentication, to which I want to use the App\AppAdmin model and app_admins table and not the App\User model and users table that voyager defaults to. I referred to the documentation to get this to work but I keep on getting errors.
From the documentation I have configured the config/voyager.php User config like so:
'user' => [
'add_default_role_on_register' => true,
'default_role' => 'user',
'admin_permission' => 'browse_admin',
'namespace' => App\AppAdmin::class,
],
The model looks like so:
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class AppAdmin extends \TCG\Voyager\Models\User
{
use Notifiable;
protected $table = 'app_admins';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
}
and also specified the target table therein above.
I added
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
and
'admins' => [
'driver' => 'eloquent',
'model' => App\AppAdmin::class,
],
To the guards and providers arrays respectively in the config/auth.php file.
This gives me this error.
Type error: Argument 1 passed to TCG\Voyager\Policies\MenuItemPolicy::checkPermission() must implement interface TCG\Voyager\Contracts\User, instance of App\User given, called in C:\xampp\htdocs\voyager\vendor\tcg\voyager\src\Policies\BasePolicy.php on line 32 (View: C:\xampp\htdocs\voyager\vendor\tcg\voyager\resources\views\menu\admin_menu.blade.php) (View: C:\xampp\htdocs\voyager\vendor\tcg\voyager\resources\views\menu\admin_menu.blade.php) (View: C:\xampp\htdocs\voyager\vendor\tcg\voyager\resources\views\menu\admin_menu.blade.php) (View: C:\xampp\htdocs\voyager\vendor\tcg\voyager\resources\views\menu\admin_menu.blade.php)
I am not sure how to deal with this, any help is much appreciated.
Apologies in advance if am duplicating the question, I just failed to go through all the issues for my specific problem.
Voyager uses Laravel's default auth functionality, so I'm not sure you'll be able to separate that like you're looking to do.
The challenge I have is that I don't want to combine the users in one table because there could be thousands of customers with only a handful of app admins. Adding the role_id column in the users table just to accommodate the admin users doesn't seem very efficient. I am also using other third parties like Dingo Api and tymodesigns JWT which all target the default auth. The best way all three can work together out-of-the-box is by having one users used for authentication. This however reduces control and flexibility to one auth channel in the app that is attached to the laravel's default method.
agree with you @pkitatta , I also have the same question. I want voyager use other admin tables rather than users table, since user table is for normal login user in front web. These two table should not be combine together.
It should be a very common scenario that most web will encounter.
Implemented in https://github.com/the-control-group/voyager/pull/3968
This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.
Most helpful comment
agree with you @pkitatta , I also have the same question. I want voyager use other admin tables rather than users table, since user table is for normal login user in front web. These two table should not be combine together.
It should be a very common scenario that most web will encounter.