/**
  * Delete the specified resource in storage
  * @param $id
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($id)
 {
     $delRel = Permission::where('id', $id)->delete();
     if ($delRel) {
         return $this->toIndex('删除成功');
     } else {
         return $this->toIndex('删除失败');
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->call('migrate');
     $role = Role::create(['name' => 'admin', 'display_name' => '超级管理员']);
     $permission = Permission::create(['name' => 'admin', 'display_name' => '超级管理员权限']);
     $user = User::create(['name' => '超级管理员', 'email' => env('ADMIN_EMAIL', '*****@*****.**'), 'password' => bcrypt(env('ADMIN_PASSWORD', 'admin'))]);
     $role->attachPermission($permission);
     $user->attachRole($role);
     $this->info('Forone initialized!');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int $id
  * @return Response
  */
 public function update($id, Request $request)
 {
     $data = $request->except('_token');
     Permission::findOrFail($id)->update($data);
     return $this->toIndex('编辑成功');
 }
示例#4
0
 public function permissions()
 {
     $permissions = Permission::join('permission_role', 'permissions.id', '=', 'permission_role.permission_id')->where('permission_role.role_id', '=', $this->id)->get();
     return $permissions;
 }
 /**
  * 分配权限
  */
 public function assignPermission(Request $request)
 {
     $role = Role::find($request->get('id'));
     $permissions = $request->except(['_token', 'id']);
     $role->detachPermissions($role->permissions());
     foreach ($permissions as $name => $status) {
         $permission = Permission::whereName($name)->first();
         if ($status == 'on') {
             $role->attachPermission($permission);
         }
     }
     return $this->toIndex('权限分配成功');
 }