상속: extends Illuminate\Database\Eloquent\Model
 public function run()
 {
     Entity::create(['name' => 'role']);
     Entity::create(['name' => 'entity']);
     Entity::create(['name' => 'permission']);
     Entity::create(['name' => 'assignment']);
 }
 /**
  * @param $name
  * @return mixed
  */
 public function destroy($name)
 {
     $entity = Entity::find($name);
     $this->authorize('remove', $entity);
     $entity->delete();
     $this->resetSuperAdminPermissions();
     return redirect()->route('genealabs.laravel-governor.entities.index');
 }
예제 #3
0
 protected function resetSuperAdminPermissions()
 {
     Permission::where('role_key', 'SuperAdmin')->delete();
     $entities = Entity::all();
     $actions = Action::all();
     foreach ($entities as $entity) {
         foreach ($actions as $action) {
             Permission::updateOrCreate(['role_key' => 'SuperAdmin', 'entity_key' => $entity->name, 'action_key' => $action->name, 'ownership_key' => 'any']);
         }
     }
 }
 public function run()
 {
     $superadmin = Role::whereName('SuperAdmin')->get()->first();
     $actions = Action::all();
     $ownership = Ownership::whereName('any')->get()->first();
     $entities = Entity::all();
     foreach ($entities as $entity) {
         foreach ($actions as $action) {
             $permission = new Permission();
             $permission->role()->associate($superadmin);
             $permission->action()->associate($action);
             $permission->ownership()->associate($ownership);
             $permission->entity()->associate($entity);
             $permission->save();
         }
     }
 }
예제 #5
0
 /**
  * @param $name
  * @return mixed
  */
 public function update(UpdateRoleRequest $request, $name)
 {
     $role = Role::find($name);
     $role->fill($request->only(['name', 'description']));
     if ($request->has('permissions')) {
         $allActions = Action::all();
         $allOwnerships = Ownership::all();
         $allEntities = Entity::all();
         $role->permissions()->delete();
         foreach ($request->get('permissions') as $entity => $actions) {
             foreach ($actions as $action => $ownership) {
                 if ('no' !== $ownership) {
                     $currentAction = $allActions->find($action);
                     $currentOwnership = $allOwnerships->find($ownership);
                     $currentEntity = $allEntities->find($entity);
                     $currentPermission = new Permission();
                     $currentPermission->ownership()->associate($currentOwnership);
                     $currentPermission->action()->associate($currentAction);
                     $currentPermission->role()->associate($role);
                     $currentPermission->entity()->associate($currentEntity);
                     $currentPermission->save();
                 }
             }
         }
     }
     $role->save();
     return redirect()->route('genealabs.laravel-governor.roles.index');
 }
 /** @test */
 public function it_gets_permissions()
 {
     $this->prepare();
     $entity = Entity::with('permissions')->find('role');
     $this->assertGreaterThan(4, $entity->permissions->count());
 }