Meteor Newbie
Meteor Newbie

Reputation: 686

Laravel: how to distinguish normal user, moderator and admin

I want to have users with different roles and permissions - for example normal user - readonly, mods - edit/delete, admins - create/delete/edit. By default Laravel provides users model with migration. I read, for this purpose there should be additional tables for roles and permission. But I have no idea what structure this tables should have and what to do next. Are there any good tutorial for beginners for my question or can someone post an easy example?

Upvotes: 1

Views: 1388

Answers (2)

Sletheren
Sletheren

Reputation: 2486

You can always use a package like https://github.com/spatie/laravel-permission, or you can create your own, here is the algorithm for you.

1- Create a table/Model called Roles.

2- Set up the relationship to be 1 to many (if you want a user to have multiple permissions) or 1 to 1 (if you want the user to have one permission)

3- create a middleware called RolesMiddlware per example, that gonna check after every route call, if the user has permission depending on the roles he has, if he has the appropriate permission then proceed otherwise return an error.

Upvotes: 3

Quezler
Quezler

Reputation: 2435

From what i can find this is the most beginner friendly laravel permissions package

Upvotes: 2

Related Questions