database/seeds/RolesPermissionsSeeder.php
/**
     * Run the database seeds.
     *
     * @return void
     */
Run the database seeds.
@return void
Run the database seeds . @return void
public function run(Role $role, Permission $permission)
    {
        $allPermissions = $permission->defaultPermissions();
        foreach ($allPermissions as $perms) {
            Permission::query()->firstOrCreate(['name' => $perms]);
        }
        $this->command->info('Default Permissions added.');
        $role = Role::query()->firstOrCreate(['name' => Role::SYSADMIN]);
        $role->syncPermissions($permission->all());
        $this->command->info('Super Admin role created and granted all permissions' . "\n");
        $this->createUser($role);
        $this->command->info('Super Admin User created');
        $role = Role::query()->firstOrCreate(['name' => Role::ADMIN]);
        $allPermissions = $permission->getAdminPermissions();
        $admin_permissions = $permission->whereIn('name', $allPermissions)->pluck('name');
        $role->syncPermissions($admin_permissions);
        $this->command->info('Admin User role created successfully.');
        $this->createUser($role);
        $this->command->info('Admin User created');
        $role = Role::query()->firstOrCreate(['name' => Role::INTERNAL_USER]);
        $allPermissions = $permission->getInternalUserPermissions();
        $internal_user_permissions = $permission->whereIn('name', $allPermissions)->pluck('name');
        $role->syncPermissions($internal_user_permissions);
        $this->command->info('Internal user role created successfully.');
        $role = Role::query()->firstOrCreate(['name' => Role::VENDOR]);
        $allPermissions = $permission->getVendorPermissions();
        $vendor_permissions = $permission->whereIn('name', $allPermissions)->pluck('name');
        $role->syncPermissions($vendor_permissions);
        $this->createUser($role);
        $this->command->info('Default roles created successfully.');
        $this->command->warn('All done :)');
    }
public function run ( Role $ role , Permission $ permission ) { $ allPermissions = $ permission -> defaultPermissions ( ) ; foreach ( $ allPermissions as $ perms ) { Permission :: query ( ) -> firstOrCreate ( [ 'name' => $ perms ] ) ; } $ this -> command -> info ( 'Default Permissions added.' ) ; $ role = Role :: query ( ) -> firstOrCreate ( [ 'name' => Role :: SYSADMIN ] ) ; $ role -> syncPermissions ( $ permission -> all ( ) ) ; $ this -> command -> info ( 'Super Admin role created and granted all permissions' . " \n " ) ; $ this -> createUser ( $ role ) ; $ this -> command -> info ( 'Super Admin User created' ) ; $ role = Role :: query ( ) -> firstOrCreate ( [ 'name' => Role :: ADMIN ] ) ; $ allPermissions = $ permission -> getAdminPermissions ( ) ; $ admin_permissions = $ permission -> whereIn ( 'name' , $ allPermissions ) -> pluck ( 'name' ) ; $ role -> syncPermissions ( $ admin_permissions ) ; $ this -> command -> info ( 'Admin User role created successfully.' ) ; $ this -> createUser ( $ role ) ; $ this -> command -> info ( 'Admin User created' ) ; $ role = Role :: query ( ) -> firstOrCreate ( [ 'name' => Role :: INTERNAL_USER ] ) ; $ allPermissions = $ permission -> getInternalUserPermissions ( ) ; $ internal_user_permissions = $ permission -> whereIn ( 'name' , $ allPermissions ) -> pluck ( 'name' ) ; $ role -> syncPermissions ( $ internal_user_permissions ) ; $ this -> command -> info ( 'Internal user role created successfully.' ) ; $ role = Role :: query ( ) -> firstOrCreate ( [ 'name' => Role :: VENDOR ] ) ; $ allPermissions = $ permission -> getVendorPermissions ( ) ; $ vendor_permissions = $ permission -> whereIn ( 'name' , $ allPermissions ) -> pluck ( 'name' ) ; $ role -> syncPermissions ( $ vendor_permissions ) ; $ this -> createUser ( $ role ) ; $ this -> command -> info ( 'Default roles created successfully.' ) ; $ this -> command -> warn ( 'All done :)' ) ; }
Run the database seeds.
Run the database seeds .
//        DB::table('users')->truncate(); //        DB::table('internal_users')->truncate(); //        DB::table('vendors')->truncate(); // Seed the default permissions //            error_log($perms . ': "' . $perms . '",'); //        if (true) { //            return; //        } //super admin //admin //internal user //vendors