Geen omschrijving
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CreateUserSeeder.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. use Illuminate\Database\Seeder;
  3. use App\User;
  4. use Illuminate\Support\Facades\DB;
  5. use Spatie\Permission\Models\Role;
  6. use Spatie\Permission\Models\Permission;
  7. use Illuminate\Support\Facades\Hash;
  8. class CreateUserSeeder extends Seeder
  9. {
  10. /**
  11. * Run the database seeds.
  12. *
  13. * @return void
  14. */
  15. public function run()
  16. {
  17. //
  18. DB::beginTransaction();
  19. $user = User::create([
  20. 'name' => 'admindoni',
  21. 'email' => 'admindoni@mail.com',
  22. 'password' => Hash::make('123456')
  23. ]);
  24. $role = Role::create(['name' => 'Super Admin']);
  25. $permissions = Permission::pluck('id', 'id')->all();
  26. $role->syncPermissions($permissions);
  27. $user->assignRole([$role->id]);
  28. $permission = [
  29. 'role-create',
  30. 'role-delete',
  31. 'role-update',
  32. 'role-list',
  33. 'permission-create',
  34. 'permission-delete',
  35. 'permission-update',
  36. 'permission-list',
  37. 'user-create',
  38. 'user-delete',
  39. 'user-update',
  40. 'user-list',
  41. ];
  42. foreach ($permission as $key => $value) {
  43. $create_permission = Permission::create(['name' => $value]);
  44. DB::insert('insert into role_has_permissions (permission_id, role_id) values (?, ?)', [$create_permission->id, $role->id]);
  45. }
  46. DB::commit();
  47. }
  48. }