/** * 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 = Admin::create(['name' => '超级管理员', 'email' => env('ADMIN_EMAIL', '*****@*****.**'), 'password' => bcrypt(env('ADMIN_PASSWORD', 'admin'))]); $role->attachPermission($permission); $user->attachRole($role); $this->info('Forone initialized!'); }
/** * 分配权限 */ 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('权限分配成功'); }
public function permissions() { $permissions = Permission::join('permission_role', 'permissions.id', '=', 'permission_role.permission_id')->where('permission_role.role_id', '=', $this->id)->get(); return $permissions; }
/** * 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('编辑成功'); }