/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Role::create(['slug' => 'role:view', 'description' => 'View roles']);
     Role::create(['slug' => 'rolegroup:view', 'description' => 'View rolegroups']);
     Role::create(['slug' => 'rolegroup:write', 'description' => 'Manage rolegroups']);
     Role::create(['slug' => 'rolegroup:delete', 'description' => 'Delete rolegroups']);
 }
Esempio n. 2
0
 /**
  *  Index
  *  Find all Role.
  *
  *  @param  $payload
  *  @return boolean
  **/
 public function index($payload)
 {
     # Validate
     $userId = Guardian::userId();
     $user = User::find((int) $userId);
     $account = $user->accounts->first();
     Guardian::check($account->getId(), 'role:view');
     # return roles
     return Role::orderBy('id')->get()->map(function ($role) use($payload) {
         return $role->schema($payload->display);
     });
 }
Esempio n. 3
0
 /**
  *  Patch
  *  Update an existing rolegroup.
  *
  *  @param $payload
  *  @return object
  **/
 public static function update($payload)
 {
     # Validate
     $userId = Guardian::userId();
     $user = User::find((int) $userId);
     $account = $user->accounts->first();
     Guardian::check($account->getId(), 'rolegroup:write');
     DB::beginTransaction();
     try {
         # Save input (name and description)
         $rolegroup = Rolegroup::find($payload->id);
         if (!$rolegroup) {
             throw new ModelNotFoundException();
         }
         $rolegroup->schemaUpdate((array) $payload);
         $rolegroup->roles()->detach();
         if (isset($payload->roles)) {
             $roles = Role::find($payload->roles);
             $rolegroup->roles()->attach($roles);
         }
     } catch (\Exception $e) {
         DB::rollback();
         throw $e;
     }
     DB::commit();
     # Return created rolegroup with respective roles (permissions)
     return $rolegroup->schema($payload->display);
 }