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

Kenpachi Zaraki
2 min readJun 25, 2021

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

We wish to create a simple blog. To do this, we decide we need a rich text editor for bloggers to use in writing articles. We also need to store data about articles, writers and readers who sign up onto the blog.

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. Articles: this model will store information about articles written on the website.
  2. User: this model will store information about users of the website.

User Roles and Permissions

Below are the three roles users will have on the website and the permissions they are allowed for each Model.

1. admin

Article: read, delete

User: create, read, update, delete

2. writer

Article: create, read, update, delete

User: create, read, update

3. reader

Article: read

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 Articles

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

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

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

Laravel 8: MySQL Database Query Tip Sheet #4

--

--