Wednesday, October 19, 2022

[FIXED] What is the better wat ro create admin role in Laravel?

Issue

I want to create simple SPA with admin-panel. I did panel and fronted part. Now I have two solutions way:

  • Use enum type of row in database: $table->enum('role', ['user', 'admin]);
  • Create another 'roles' table and insert there: 'user' and 'admin' Which is the better way and why?

Solution

Always try to go for the simplest, clearest solution. As long a you only have 2 roles, admin and user, and a customer can only have one role, the first solution is much easier.

Defining a new table would give unwanted complexity, and also to ask for each user it's role from a different table could be timeconsuming.

Perhaps if you have more roles, and a user can have multiple roles, the second solution is more clear.



Answered By - Mátyás GrÅ‘ger
Answer Checked By - Candace Johnson (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.