mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-12 05:11:07 +03:30
fix
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use App\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class AccessSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
if ( $this->assignAllRoleToAdministrator() ) {
|
||||
dump( 'Success.' );
|
||||
} else {
|
||||
dump( 'Error: Please Check And Run Again.' );
|
||||
}
|
||||
}
|
||||
|
||||
private function assignAllRoleToAdministrator()
|
||||
{
|
||||
$roleModel = new Role();
|
||||
if ( $roleModel->where( 'name' , 'administrator' )->first() == null ) {
|
||||
Role::create( [
|
||||
'name' => 'administrator'
|
||||
] );
|
||||
}
|
||||
|
||||
// assign role to user id 1
|
||||
$user = User::find( 1 );
|
||||
$user->assignRole( 'administrator' );
|
||||
|
||||
// get all permission
|
||||
$permissions = [];
|
||||
foreach ( Permission::all() as $item ) {
|
||||
$permissions[ 'permissions' ][ $item ] = "1";
|
||||
}
|
||||
|
||||
// assign all permissions to role administrator
|
||||
foreach ($permissions['permissions'] as $permission) {
|
||||
$role = Role::where('id', 1)->first();
|
||||
$role->syncPermissions(array_keys($permission));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user