Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cmdobueno's avatar

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');
        });
    }
0 likes
2 replies
cmdobueno's avatar

@ardnor

My end goal is use as few prebuild packages. This is for a system that has a long life, and there will in the end be some very "special" things I have to do with the permission system. The permission system will need to possibly span SaaS, and be bound to certain domain names. I just feel more comfortable customizing something I have built.

I have used the above package to large amounts of success on other projects and it is a very well build package no doubt.

1 like

Please or to participate in this conversation.