database/seeders/RoleSeeder.php
/**
     * Run the database seeds.
     *
     * @return void
     */
Run the database seeds.
@return void
Run the database seeds . @return void
public function run()
    {
        $admin = Role::factory()->create([
            'name' => 'Admin'
        ]);
        $editor = Role::factory()->create([
            'name' => 'Editor'
        ]);
        $viewer = Role::factory()->create([
            'name' => 'Viewer'
        ]);
        $permissions = Permission::all();
         $admin->permissions()->attach($permissions->pluck('id'));
         $editor->permissions()->attach($permissions->pluck('id'));
         $editor->permissions()->detach(4);
         $viewer->permissions()->attach([1, 3, 5, 7]);
    }
public function run ( ) { $ admin = Role :: factory ( ) -> create ( [ 'name' => 'Admin' ] ) ; $ editor = Role :: factory ( ) -> create ( [ 'name' => 'Editor' ] ) ; $ viewer = Role :: factory ( ) -> create ( [ 'name' => 'Viewer' ] ) ; $ permissions = Permission :: all ( ) ; $ admin -> permissions ( ) -> attach ( $ permissions -> pluck ( 'id' ) ) ; $ editor -> permissions ( ) -> attach ( $ permissions -> pluck ( 'id' ) ) ; $ editor -> permissions ( ) -> detach ( 4 ) ; $ viewer -> permissions ( ) -> attach ( [ 1 , 3 , 5 , 7 ] ) ; }
Run the database seeds.
Run the database seeds .
//made custom role //write role-permissions table //        foreach ($permissions as $permission) { //          \DB::table('role_permissions')->insert([ //             'permissions_id' => $permission ->id, //             'role_id' => $admin->id //          ]); //} //or better //admin //editor //exclude number 4 editor role not have permissions //viewer attach only view permission