Beispiel #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // Roles
     $admin = new Role();
     $admin->name = 'admin';
     $admin->display_name = 'Admin';
     $admin->description = 'Administration users';
     $admin->save();
     $user = new Role();
     $user->name = 'user';
     $user->display_name = 'User';
     $user->description = 'Registered users';
     $user->save();
     // Permissions
     $permission_user = new Permission();
     $permission_user->name = 'user-administration';
     $permission_user->display_name = 'User: Administration';
     $permission_user->description = 'CRUD users';
     $permission_user->save();
     $permission_video = new Permission();
     $permission_video->name = 'video-administration';
     $permission_video->display_name = 'Video: Administration';
     $permission_video->description = 'CRUD video';
     $permission_video->save();
     $admin->attachPermissions([$permission_user, $permission_video]);
     // User
     $admin_user = User::create(['name' => 'admin', 'email' => '*****@*****.**', 'password' => 'admin']);
     $admin_user->attachRole($admin);
 }
Beispiel #2
0
 public function createPermission($modulName, $permissionType)
 {
     $slugModule = strtolower($modulName);
     $slugModule = str_replace(' ', '_', $slugModule);
     $slugModule = $slugModule . '-' . $permissionType;
     return Permission::create(['name' => $slugModule, 'display_name' => $modulName . ' ' . $permissionType, 'description' => '']);
 }
Beispiel #3
0
 /**
  * Formbuilder.
  *
  * @param null $form
  * @param \Illuminate\Database\Eloquent\Model|null $entry
  *
  * @return mixed
  */
 public function getForm($form = null, Model $entry = null)
 {
     $selectedPermissions = null;
     if (!is_null($entry)) {
         // only for edit
         $selectedPermissions = $entry->perms->pluck('id')->toArray();
     }
     $permissions = Permission::pluck('display_name', 'id');
     $formFields = ['id' => $form->hidden('id'), 'name' => $form->text(trans('user::role.name'), 'name'), 'display_name' => $form->text(trans('user::role.display-name'), 'display_name'), 'description' => $form->text(trans('user::role.description'), 'description'), 'permissions' => $form->select(trans('user::permission.permissions'), 'permissions')->options($permissions)->multiple()->select($selectedPermissions), 'submit' => $form->submit(trans('crud::crud.save'))];
     return $formFields;
 }