@cmdobueno why not using package like this --> https://github.com/spatie/laravel-permission it will saves you time. I use this for multiple projects.
Aug 31, 2018
2
Level 18
Roles/Permissions/Users Review
Hey everybody,
Please review my permission/roles concept. I am very interested in the concept of permissions being able to be grouped by group_slug (see migration). I am not sure if this is better than having a dedicated table or not... let me know your thoughts.
public function up()
{
Schema::create('roles', function(Blueprint $table) {
$table->increments('id')->unsigned();
$table->string("slug")->unique();
$table->string("name");
$table->text("description")->nullable();
$table->boolean("locked")->default(false);
$table->boolean("all")->default(false);
});
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('first_name');
$table->string('last_name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->unsignedInteger("role_id");
$table->boolean("disabled")->default(false);
$table->rememberToken();
$table->softDeletes();
$table->timestamps();
});
Schema::create('permissions', function(Blueprint $table) {
$table->increments('id')->unsigned();
$table->string("name");
$table->string("slug")->unique();
/*
* Rather than having a permissions group table I have opted to be able to use group by on group_slug
* Interested if this makes more sense than using a dedicated table.
*
* Permissions are rarely queried alone, only on the "roles" page.
*/
$table->string("group");
$table->string("group_slug");
$table->text("description");
$table->timestamps();
});
Schema::create('permission_role', function(Blueprint $table) {
$table->unsignedInteger("permission_id");
$table->unsignedInteger("role_id");
$table->foreign('permission_id')->references('id')
->on('permissions')
->onDelete('cascade');
$table->foreign('role_id')->references('id')
->on('roles')
->onDelete('cascade');
});
}
Level 6
Please or to participate in this conversation.