예제 #1
0
 /**
  * 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!');
 }
 /**
  * 分配角色
  */
 public function assignRole(Request $request)
 {
     $user = User::find($request->get('id'));
     $roles = $request->except(['_token', 'id']);
     $user->detachRoles($user->roles()->get());
     foreach ($roles as $name => $status) {
         $role = Role::whereName($name)->first();
         if ($status == 'on') {
             $user->attachRole($role);
         }
     }
     return $this->toIndex('角色分配成功');
 }
 /**
  * Delete the specified resource in storage
  * @param $id
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($id)
 {
     if (Role::destroy($id)) {
         return $this->toIndex('删除成功');
     } else {
         return $this->toIndex('删除失败');
     }
 }
예제 #4
0
 /**
  * 分配权限
  */
 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('权限分配成功');
 }