Laravel multi-auth different table for admin and user but one login page - laravel

Is it possible to have two different tables for users and admin but one login page? I already used middleware and Spatie permission, but I need them to separate because some info doesn't match if they are together in one table.
For example:
Admin needs name, employee number. At the same time, users need a name, address, student number, etc.
I need suggestions on how to do that to study it.

Related

Laravel Multi table auth

I have three tables
Admins for admin,
Teachers for teacher,
students for student.
Each of these users have their own dashboard (AdminDash, TeacherDash, StudentDash). Now all I want to do is, each user are sent to their respective dashboard after login. Is it even possible to do so.
Also can this be done using single login form or do I need to create different login form for each case and different controllers to authenticate.
Edit:
Actually, here teachers and students fill different registration forms with different value so I don't want to store them in same table. And admins is for admin and superadmin who run the site. Also the dashboard they use after login are different.
I published a custom laravel for manage multi auth in one laravel project. In example branch I commit step by step for describe everything you most know. larasin
Also can this be done using single login form or do I need to create different login form for each case and different controllers to authenticate.
You can create a login form component an use it every where you want.
First extend your 3 tables with Authenticable like:
class User extends Authenticatable
Then in your config/auth, set up the providers like:
'teachers' => [
'driver' => 'eloquent',
'model' => App\Models\Teacher::class,
],
Then you should be able to auth::attempt your model instance.
Do let me know if this doesn't work, I am pretty new in Laravel also :) cheers!
p/s: I do think it is better to just use a user table with a "role" column, however I believe you probably have different columns needed for each of these user groups. But you can still use new tables such as "teacher_profiles","user_profiles" for those columns, and you can refer to different tables according to your role.
For example, if "teacher" role_id is 3, then if user role==3, you will refer to "teacher_profiles" table.

creating Multiple Authentication Laravel 5.5

I plan to develop a system that has three two types (admin, users). I want to have each user types information stored in a separate table for easy access and to reduce the number of blank fields (if they were all in one table).
i need all users login in the same login form not separated form for each one of them

Laravel 5.1 Sync user to other users

I build a Laravel app.
In table users I have 2 kinds of users - one user is restaurants and another user is restaurant stuff.
What I exactly need?
I want to sync user (res stuff) to user (restaurant). Is that possible or I need to move the restaurant to the other table and then sync?
I'm looking just for the idea and is that possible?
What is the difference between the user in the same table is admin field - res users have value '999' at admin column and res stuff has value '1' at admin column.

Multi Tenancy approach - UserId to N Tenants

Can I register same user (login/e-mail) in more than on tenant, so an UserId can belong to multiple Tenants?
I ask that because instead of input Tenant on login, How hard is to achieve this approach below?
When user logs in, if they belong to multiple tenants, boilerplate will identify this and show the user a select dropdown to choose which tenant they want to manage.
I feel this approach is more professional than input a tenant string value on login page.
it's not possible in aspnetboilerplate structure. a user must belong to only a single tenant.

Laravel authorization via email, password and additional field

Out of the box Laravel authorizes users by matching email (default - can be overridden) and password.
Is it possible to authorize user using 3 fields, e.g:
email
password
group
... where 'group' is some additional field from 'users' database.
In other words, user can belong to group:1 and can login to group:1 resources only, but not to group:2 using his group:1 credentials.
If user belongs to group:1 and group:2, then he needs different credentials to login to either group.
Additionally, user can use same email for both groups. In such case it is group number that would act as additional identifier. And of course passwords would be different.
I am thinking setting a database multiple column index on fields 'id' and 'group' would be a good start, but I fail to grasp (yet), what would be required to make Laravel authorization process sensitive to 3 fields, instead of 2.
I would appreciate some pointers.
This sounds like you're trying to achieve a form of tenancy on data belonging to certain groups only. Have a look at this package:
https://github.com/HipsterJazzbo/Landlord
In essence, you would add a group_id field to the tables where you wish to restrict access and then using middleware, apply an additional where('group_id', Auth::user()->group_id) clause to any database queries. This works very well for retrieving subsets of data belonging to specific users by their role, for example.

Resources