I have two type user.
And two table for them.
1. technicians
2. requesters
Is there any way to Multiple authentication in laravel 5.1?
I see and read this post.
Laravel 5.1 multiple authentication
but I am not separate users by group_id in users table.
I want save user and password in each table.
technicians user , pass save in technician table and requsters too.
is there any way?
by the way each table has special roules
-
why not have only one table for users then a user can belong to technicians or requesters, then use Laravel hasOne relationship or belongsTo, no need for multiple users , not the bestEmeka Mbah– Emeka Mbah2015-12-17 07:09:28 +00:00Commented Dec 17, 2015 at 7:09
-
I think what you are looking for is role based authentication. It's not a good idea to save different types of users to different tables. You could Entrust for laravel.Saad– Saad2015-12-17 07:12:58 +00:00Commented Dec 17, 2015 at 7:12
-
thanks, If I use one table, requsters change group_id and become to technicians. if requester is hacker and bypass the group_idparanoid– paranoid2015-12-17 07:18:03 +00:00Commented Dec 17, 2015 at 7:18
Add a comment
|
1 Answer
You can install this package: https://github.com/Kbwebs/MultiAuth
Please read the documentation.
In this package you can create multiple auth. This will override the laravel's auth system.
For example you want to create auth for user and admin.
In the config/auth.php you define the 2 auth:
'multi-auth' => [
'admin' => [
'driver' => 'eloquent',
'model' => App\Admin::class
],
'user' => [
'driver' => 'eloquent',
'model' => App\User::class
]
]
Also your auth syntax will change, please see image below that will show you camparison in syntax, how to login a user and admin versus the Default laravel auth syntax:
