RolesAndPermissionsSeeder add seeder inside database->seeds->file have to declare this in DatabaseSeeder _____________________________________________________________________________________________________________ Modify the Roles and Permission Model that exists on the following namespace App\Containers\Authorization\Models _____________________________________________________________________________________________________________ Add the CLI comment to update the existing roles based on roles table App\Containers\Common\UI\CLI\Commands - namespace _____________________________________________________________________________________________________________ Migration for Role and permissions - TableCheck.php It will also seed the RolesAndPermissionsSeeder and assign role to admin[already exists in DB] Remember to add the namespace of Artisan at top of TableCheck.php if (!Schema::hasTable('roles')) { Schema::create('roles', function (Blueprint $table) { $table->increments('id'); $table->string('name', 50)->unique(); $table->string('display_name', 50); $table->string('description', 150)->nullable(); $table->boolean('all')->default(false); $table->boolean('locked')->default(false); $table->unsignedInteger('created_by')->default(1); $table->timestamps(); $table->foreign('created_by') ->references('id') ->on('admin') ->onDelete('cascade'); }); } if (!Schema::hasTable('role_user')) { Schema::create('role_user', function (Blueprint $table) { $table->unsignedInteger('user_id'); $table->unsignedInteger('role_id'); $table->foreign('user_id') ->references('id') ->on('admin') ->onDelete('cascade'); $table->foreign('role_id') ->references('id') ->on('roles') ->onDelete('cascade'); $table->primary(['user_id', 'role_id']); }); } if (!Schema::hasTable('permissions')) { Schema::create('permissions', function (Blueprint $table) { $table->increments('id'); $table->string('slug', 50)->unique(); $table->string('name', 50); $table->string('description', 150)->nullable(); $table->string('main_menu')->nullable(); $table->string('sub_menu')->nullable(); $table->string('main_link')->nullable(); $table->string('sub_link')->nullable(); $table->integer('sort')->nullable(); $table->string('head_icon')->nullable(); $table->string('icon')->nullable(); $table->timestamps(); }); } if (!Schema::hasTable('permission_role')) { Schema::create('permission_role', function (Blueprint $table) { $table->unsignedInteger('role_id'); $table->unsignedInteger('permission_id'); $table->foreign('role_id') ->references('id') ->on('roles') ->onDelete('cascade'); $table->foreign('permission_id') ->references('id') ->on('permissions') ->onDelete('cascade'); $table->primary(['role_id', 'permission_id']); }); Artisan::call('db:seed',['--class' => \RolesAndPermissionsSeeder::class]); Artisan::call('update:roles:toadmin'); } _____________________________________________________________________________________________________________ Add PanelSideLayout.php and change Layout blade file to take the layout from database Remove the DashboardEdit Btn from Dashboard blade file - as it show based on permissions _____________________________________________________________________________________________________________ Constant for roles and permissions Namespace ==> App\Base\Constants\Auth _____________________________________________________________________________________________________________ Change default model namespace in auth.php As it was User::class before 'users' => [ 'driver' => 'eloquent', 'model' => env('USER_NAMESPACE') . AdminModel::class, ], while USER_NAMESPACE is not found in .env then add it with appropriate namespace Ex: USER_NAMESPACE=App\Containers\Admin\Models\ _____________________________________________________________________________________________________________ Add laravel-permission.php config file in config directory => has table names related to roles and permissions _____________________________________________________________________________________________________________ Trait for Check Roles Add UserAccessScopeTrait.php for checking the role of user in the following namespace ==App\Traits\file.php== _____________________________________________________________________________________________________________ Add the Trait to the UserModel.php which extends all model namespace App\Ship\Parents\Models; use UserAccessScopeTrait and add the following relation: public function roles() { return $this->belongsToMany(Role::class, 'role_user', 'user_id', 'role_id'); } Namespace for Trait and Role Model.. use App\Traits\UserAccessScopeTrait; use Spatie\Permission\Models\Role; _____________________________________________________________________________________________________________ Open AdminAddSaveTask.php Change the role as of roles table and assign the role to the user and also on update task _____________________________________________________________________________________________________________ Change Dashboard function in admin controller as based on permission assigned