Emjey23
Emjey23

Reputation: 367

Modify Laravel built-in Auth for users

I am using Laravel built-in Authentication for users which I run from the terminal php artisan make:auth

It has one table in the database, users table and has an isAdmin column, so I am assuming it has two roles an admin and not_amin account.

Now, what I want is to modify this built-in functionality of Laravel make:auth to be able to add some roles like isEmployee and/or isCustomer.

How can I achieve this using the available option I have? I hope, I somewhat explained my case. Thanks.

Upvotes: 2

Views: 276

Answers (1)

Mihir Bhende
Mihir Bhende

Reputation: 9055

Having a column is_admin is targeted to only one role. This tells you if user is an admin or not.

I would suggest you to change depending on any of below cases :

1. If user can have just 1 role :

Modify users table and change is_admin to role. Inside role column, you can store the role of that particular user like admin, employee, 'customer` etc.

2. If user has multiple roles(many-to-many) :

Remove column is_admin from users table and create a new table role_user which will have user_id and role_id. You will need to have another table called roles to store all available roles in your system.

Upvotes: 1

Related Questions