Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,148,896 members, 7,802,886 topics. Date: Saturday, 20 April 2024 at 01:43 AM

How To Create Multiple User Authentication In Laravel 5.3 - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / How To Create Multiple User Authentication In Laravel 5.3 (2650 Views)

Codeigniter 3 Vs Php Laravel 5.8 : Which One Will You Go For? / Scratch Card System In Laravel / Generating Fake Data In Laravel 5.8 | Laravel Seeding (2) (3) (4)

(1) (Reply) (Go Down)

How To Create Multiple User Authentication In Laravel 5.3 by mohemos: 10:58pm On Nov 29, 2016
Laravel 5.3 gurus, please help me as am new to Laravel framework.
Now I have a system am building, the system has 4 different types of users e.g

*Student Login

*Lecturer Login

*Admin Login

*Counsellor Login

each of them has their different tables in the database.

Laravel comes with just a single user authentication using the users table.

please how can I go about this ?
Thanks in advance!
Re: How To Create Multiple User Authentication In Laravel 5.3 by jidez007: 11:11pm On Nov 29, 2016
You should not create different tables for similar contents. You can just have 1 user table and have a type column, that will specify the type of user.

However I think it's possible that a lecturer can also be an admin, the lecturer shouldn't have to logout first before he can now login as admin.

You can have a separate roles table, and a user_role pivot table to assign multiple roles to a user. This package does everything seemlessly https://github.com/Zizaco/entrust
Re: How To Create Multiple User Authentication In Laravel 5.3 by talk2hb1(m): 12:58am On Nov 30, 2016
This is a role privilege concept solution. Lecturer, students, counselor, and Admin are all roles so you have a table for keeping roles, and another table for keeping all users. Users belongs to a role and a role can have many users too; this concept means your application will be scalable and flexible enough for your users to add more roles in the future without writing any code if done properly
Re: How To Create Multiple User Authentication In Laravel 5.3 by mohemos: 1:00am On Nov 30, 2016
jidez007:
You should not create different tables for similar contents. You can just have 1 user table and have a type column, that will specify the type of user.

However I think it's possible that a lecturer can also be an admin, the lecturer shouldn't have to logout first before he can now login as admin.

You can have a separate roles table, and a user_role pivot table to assign multiple roles to a user. This package does everything seemlessly https://github.com/Zizaco/entrust

Thanks, I've used that method, I just use student, lecturer, admin as example. The app am working on is something far different and is a requirement that each entity has its table
Re: How To Create Multiple User Authentication In Laravel 5.3 by mohemos: 1:14am On Nov 30, 2016
talk2hb1:
This is a role privilege concept solution. Lecturer, students, counselor, and Admin are all roles so you have a table for keeping roles, and another table for keeping all users. Users belongs to a role and a role can have many users too; this concept means your application will be scalable and flexible enough for your users to add more roles in the future without writing any code if done properly
Thanks but the database has been built and populated already, the system was built on raw php before, I just wanna use laravel to add new features to it.
Re: How To Create Multiple User Authentication In Laravel 5.3 by FrankLampard: 5:37am On Nov 30, 2016
You should implement a guard so you can authenticate from each guard. Like this.

$validate->only($request['username'], $request['password'];

Auth::guard('table-name')->attempt ($validate){
//Authenticates.
}

But the ugly part with this method is that you have to do the ugly checking of not allowing specific user to gain access to another users routes or view.

Hope it helps any problem feel free to ask.

1 Like

Re: How To Create Multiple User Authentication In Laravel 5.3 by talk2hb1(m): 12:02pm On Nov 30, 2016
mohemos:

Thanks but the database has been built and populated already, the system was built on raw php before, I just wanna use laravel to add new features to it.
You can always transfer if you want to, all you need to do is write a simple script that will automate that for you undecided
Re: How To Create Multiple User Authentication In Laravel 5.3 by Nobody: 4:29am On Dec 01, 2016
FrankLampard:
You should implement a guard so you can authenticate from each guard. Like this.

$validate->only($request['username'], $request['password'];

Auth::guard('table-name' )->attempt ($validate){
//Authenticates.
}

But the ugly part with this method is that you have to do the ugly checking of not allowing specific user to gain access to another users routes or view.

Hope it helps any problem feel free to ask.
Guards aren't table names. Are they?
Re: How To Create Multiple User Authentication In Laravel 5.3 by FrankLampard: 6:25am On Dec 01, 2016
Jregz:

Guards aren't table names. Are they?

It is not a must you name your guard equivalent to your table name. I only do it for the sack of remembrance.
Re: How To Create Multiple User Authentication In Laravel 5.3 by FrankLampard: 6:26am On Dec 01, 2016
talk2hb1:

You can always transfer if you want to, all you need to do is write a simple script that will automate that for you undecided

Pls how I want to learn.
Re: How To Create Multiple User Authentication In Laravel 5.3 by Nobody: 9:02am On Dec 01, 2016
FrankLampard:


It is not a must you name your guard equivalent to your table name. I only do it for the sack of remembrance.
Ok... I thought you took guards as tables
Re: How To Create Multiple User Authentication In Laravel 5.3 by bot101(m): 10:00pm On Dec 03, 2016
You'll have to define a guard and a driver (in your case, probably session) and an eloquent user model for it. Then you can call Auth::guard('guard')->attempt().

If using session driver, your users table must have a username and password column. If using token driver, it must have an api_token column.
Re: How To Create Multiple User Authentication In Laravel 5.3 by tobsbola: 9:02pm On Dec 06, 2016
Hello, unfortunately I don't have a link i gave out to someone on how you can implement this.

if you don't probably mind, you can reach me just so I give you a link that solves this problem of yours tomorrow.

Best Regards.
Re: How To Create Multiple User Authentication In Laravel 5.3 by godofbrowser(m): 9:21am On Dec 08, 2016
mohemos:
Laravel 5.3 gurus, please help me as am new to Laravel framework.
Now I have a system am building, the system has 4 different types of users e.g

*Student Login

*Lecturer Login

*Admin Login

*Counsellor Login

each of them has their different tables in the database.

Laravel comes with just a single user authentication using the users table.

please how can I go about this ?
Thanks in advance!

Hi, i think if your users are having different tables, its a poor design.
Cos you'll most likely have two users with same identifier at some point unless you're doing some ugly checks.
This should have been accomplished using Eloquent relationships instead.
I don't know what you're trying to avoid, maybe you want to collect different types of data from the different types of users.
for example; you may want to store "job title" for lecturers and "department" for students. In this case you can have additional tables like "lecturers_data" and have it linked with lecturers, and another like "students_data" like that, such that you can fetch data from them using their foreign keys.

I think this is a better approach. Every other thing you need can be done with middlewares.
Goodluck!

(1) (Reply)

How Much To Ask As Salary As A Developer? / Asp.net And Wamp Server / Become A Pro In Programming For Only N6000

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 24
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.