コード例 #1
0
ファイル: UsersTableSeeder.php プロジェクト: hisambahaa/DARES
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     if (User::count()) {
         return;
     }
     User::whereNotNull('id')->delete();
     Model::unguard();
     $users = User::all();
     $users = [['id' => 1, 'name' => 'محسن بخيش', 'email' => '*****@*****.**', 'password' => bcrypt("123456")], ['name' => 'هيثم', 'email' => 'haitham.hamdy@css.edu.om ', 'password' => bcrypt("123456")], ['name' => 'سامي', 'email' => 'samialmamari@css.edu.om ', 'password' => bcrypt("123456")], ['name' => 'احمد', 'email' => 'aalkindi@css.edu.om ', 'password' => bcrypt("123456")]];
     foreach ($users as $user) {
         User::create($user);
     }
     $permissions = [['module' => 'users', 'name' => 'اضافة مستخدم', 'slug' => 'create.users'], ['module' => 'users', 'name' => 'حذف مستخدم', 'slug' => 'delete.users'], ['module' => 'users', 'name' => 'تعديل مستخدم', 'slug' => 'edit.users'], ['module' => 'users', 'name' => 'مشاهدة المستخدمين', 'slug' => 'view.users'], ['module' => 'users', 'name' => 'اضافة صلاحية', 'slug' => 'create.roles'], ['module' => 'users', 'name' => 'حذف صلاحية', 'slug' => 'delete.roles'], ['module' => 'users', 'name' => 'تعديل صلاحية', 'slug' => 'edit.roles'], ['module' => 'users', 'name' => 'مشاهدة الصلاحيات', 'slug' => 'view.roles']];
     $slugs = array_map(function ($ar) {
         return $ar['slug'];
     }, $permissions);
     $users = User::all();
     Permission::whereIn('slug', $slugs)->delete();
     foreach ($permissions as $permission) {
         $perm = Permission::create($permission);
         foreach ($users as $user) {
             $user->attachPermission($perm);
         }
     }
 }