database/seeds/PermissionRoleTableSeeder.php
/**
     * Run the database seeds.
     *
     * @return void
     */
Run the database seeds.
@return void
Run the database seeds . @return void
public function run()
    {
        $this->command->info('Associando as permissões aos papéis...');
        $permissions = Permission::all();
        $this->command->info(' Associando as permissões ao papel SuperAdmin.');
        $permissionSuperAdmin = $permissions->filter(function ($permission) {
            return $permission->slug == 'super_admin';
        });
        Role::findOrFail(1)
            ->permissions()
            ->sync($permissionSuperAdmin->pluck('id'));
        $this->command->info(' Associando as permissões ao papel Admin.');
        $permissionAdmin = $permissions->filter(function ($permission) {
            return $permission->slug != 'super_admin';
        });
        Role::findOrFail(2)
            ->permissions()
            ->sync($permissionAdmin->pluck('id'));
        $this->command->info(' Associando as permissões ao papel User.');
        $permissionUser = $permissions->filter(function ($permission) {
            return $permission->slug == 'user_profile' ||
                   $permission->slug == 'activity_access' ||
                   $permission->slug == 'activity_show' ||
                   $permission->slug == 'activity_delete' ||
                   $permission->slug == 'log_access';
        });
        Role::findOrFail(3)
            ->permissions()
            ->sync($permissionUser->pluck('id'));
    }
public function run ( ) { $ this -> command -> info ( 'Associando as permissões aos papéis...'); $ permissions = Permission :: all ( ) ; $ this -> command -> info ( ' Associando as permissões ao papel SuperAdmin.'); $ permissionSuperAdmin = $ permissions -> filter ( function ( $ permission ) { return $ permission -> slug == 'super_admin' ; } ) ; Role :: findOrFail ( 1 ) -> permissions ( ) -> sync ( $ permissionSuperAdmin -> pluck ( 'id' ) ) ; $ this -> command -> info ( ' Associando as permissões ao papel Admin.'); $ permissionAdmin = $ permissions -> filter ( function ( $ permission ) { return $ permission -> slug != 'super_admin' ; } ) ; Role :: findOrFail ( 2 ) -> permissions ( ) -> sync ( $ permissionAdmin -> pluck ( 'id' ) ) ; $ this -> command -> info ( ' Associando as permissões ao papel User.'); $ permissionUser = $ permissions -> filter ( function ( $ permission ) { return $ permission -> slug == 'user_profile' || $ permission -> slug == 'activity_access' || $ permission -> slug == 'activity_show' || $ permission -> slug == 'activity_delete' || $ permission -> slug == 'log_access' ; } ) ; Role :: findOrFail ( 3 ) -> permissions ( ) -> sync ( $ permissionUser -> pluck ( 'id' ) ) ; }
Run the database seeds.
Run the database seeds .
// atribui as permissões para o papel super_admin // atribui as permissões para o papel admin // atribui as permissões para o papel user