Ejemplo n.º 1
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $role = Role::findOrFail($id);
     $permissions = Permission::all();
     $assignedPermissions = old('permissions', $role->permissions()->lists('id')->toArray());
     return view('admin.roles.edit', compact('role', 'permissions', 'assignedPermissions'));
 }
Ejemplo n.º 2
0
 public function removePermission($permission)
 {
     if (is_string($permission)) {
         $permission = Permission::where('name', $permission)->first();
     }
     return $this->permissions()->detach($permission);
 }
Ejemplo n.º 3
0
 public function hasPermission($permission)
 {
     if (is_array($permission)) {
         foreach ($permission as $perm) {
             if ($this->hasPermission($perm)) {
                 return true;
             }
         }
     }
     if (is_string($permission)) {
         $permission = Permission::where('name', $permission)->first();
     }
     if (is_integer($permission)) {
         $permission = Permission::find($permission);
     }
     if (!$permission instanceof Permission) {
         throw new \InvalidArgumentException('Argument must be integer, string, or an instance of ' . Permission::class);
     }
     foreach ($this->roles as $assignedRole) {
         foreach ($assignedRole->permissions as $assignedPermission) {
             if ($permission->id === $assignedPermission->id) {
                 return true;
             }
         }
     }
     return false;
 }
Ejemplo n.º 4
0
 protected function definePermission(Gate $gate)
 {
     $permissions = Permission::all();
     foreach ($permissions as $permission) {
         $gate->define($permission->name, function (HasRoleAndPermission $user) use($permission) {
             return $user->hasPermission($permission);
         });
     }
 }
Ejemplo n.º 5
0
 protected function registerAcl($gate)
 {
     $gate->before(function ($user, $ability) {
         if ($user->hasRole('root')) {
             return true;
         }
     });
     $permissions = Permission::all();
     foreach ($permissions as $permission) {
         $gate->define($permission->name, function (HasRoleAndPermission $user) use($permission) {
             return $user->hasPermission($permission);
         });
     }
 }
Ejemplo n.º 6
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->info('Synchronize Permissions Entries');
     $permissions = $this->config->get('acl.permissions');
     $items = collect();
     foreach ($permissions as $name) {
         $permission = Permission::firstOrNew(['name' => $name]);
         $status = 'No Change';
         if (!$permission->exists) {
             $permission->save();
             $status = 'New';
         }
         $items->push(['id' => $permission->getKey(), 'name' => $name, 'status' => $status]);
     }
     $items = $items->sortBy('id');
     $this->table(['ID', 'Name', 'Status'], $items);
 }
Ejemplo n.º 7
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->info('Synchronize Permissions Entries');
     if ($this->option('clear')) {
         DB::statement('SET FOREIGN_KEY_CHECKS = 0;');
         DB::table(with(new Permission())->getTable())->truncate();
     }
     $enumClass = $this->config->get('laravolt.acl.permission_enum');
     $permissions = $enumClass::toArray();
     $items = collect();
     foreach ($permissions as $name) {
         $permission = Permission::firstOrNew(['name' => $name]);
         $status = 'No Change';
         if (!$permission->exists) {
             $permission->save();
             $status = 'New';
         }
         $items->push(['id' => $permission->getKey(), 'name' => $name, 'status' => $status]);
     }
     $items = $items->sortBy('id');
     $this->table(['ID', 'Name', 'Status'], $items);
 }