How to set up Laratrust | Laravel 8 User Management | Article #2

This article is the second in my series on Laratrust. The structure of the blog we are going to build will be explained in this article. It will also cover all the background information about roles and permissions we will need. Let’s do this !!!

Case Scenario

This means we will be having different types of users sign up onto the website. Each type of user will play a different role on the website. Each role comes with it own permissions. Google Docs are a great analogy here.

Aside from the owner of a Google Doc, users with access to a Google Doc can be assigned one of the roles shown in the image above. A user’s role determines what actions (permissions) the user can perform on the the document. A viewer can therefore only read the document, a commenter can only read and comment on the document and so forth. Basically, you can think of a role as a name given to a set of permissions.

In a Laravel application, Laratrust defines a role as encompassing all CRUD operations a user with that role will have over each model in the Laravel application. That is to say that permissions take one of the following forms: create, read, update and delete. Let’s therefore define our models:

Models

  1. User: this model will store information about users of the website.

User Roles and Permissions

1. admin

User: create, read, update, delete

2. writer

User: create, read, update

3. reader

User: create, read, update

Now that we have the background information we need we can proceed to building our blog in the next article.

All the best !!!

Related Information

How to set up Laratrust | Laravel 8 User Management | Article #1

Laravel 8: MySQL Database Query Tip Sheet #4