First, background permission design RBAC

RBAC: Role Base Access Control Role-based user access control, that is, permissions are assigned to roles and roles are assigned to users.

1.1 Design of role and Permission Table

If multiple roles are involved for one user, the following design is recommended.


In general, we use the following design for one user for one role:


1, create the role table

php artisan make:model Models/Role -m

2. Create a permission table

php artisan make:model Models/Node -m

Create an intermediate table for roles and permissions (without creating a model)

php artisan make:migration role_Node

There are three migration files and two models created.

4. Create another base model

php artisan make:model Models/Base

5. Modify the inheritance of node (permission) model and role model

Add user table fields

7. Role table fields

8, permission (node) table field

9. Middle table of roles and permissions (nodes)

10. Migrate files

php artisan migrate:refresh --seed

On the way to learning PHP, if you find this article helpful to you, then please pay attention to like comment 3 times, thank you, your must be another support of my blog.