laravel 调用未定义的方法 Auth guard
laravel call to undefined method Auth guard
我想防止在 Laravel 5.5 注册后登录,我已经通过注释一行做到了:
public function register(Request $request)
{
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
// $this->guard()->login($user);
return $this->registered($request, $user)
?: redirect($this->redirectPath());
}
我在 RegisterController.php
中覆盖了它
我收到这个错误:
Call to undefined method Illuminate\Auth\AuthenticationException::guard()
$guard = array_get($exception->guard(),0);
switch ($guard) {
case 'admin':
return redirect()->guest(route('admin.login'));
break;
default:
return redirect()->guest(route('login'));
break;
}
这是我的config/auth的内容:
<?php
return [
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
],
'admins' => [
'provider' => 'admins',
'table' => 'password_resets',
'expire' => 60,
],
],
];
我已经启用了多授权系统,我有一个管理员登录名和一个用户登录名,我不想在我的用户页面注册后禁用登录。
在异常中检查守卫可以这样做:
return redirect(route(auth()->guard('admin')->check() ? 'admin.login' : 'login'));
此外,如果您试图重写方法,请在 RegisterController@register
中使用 auth()
帮助程序或 Auth::
外观:
auth()->guard('admin')->login($user);
我想防止在 Laravel 5.5 注册后登录,我已经通过注释一行做到了:
public function register(Request $request)
{
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
// $this->guard()->login($user);
return $this->registered($request, $user)
?: redirect($this->redirectPath());
}
我在 RegisterController.php
中覆盖了它我收到这个错误:
Call to undefined method Illuminate\Auth\AuthenticationException::guard()
$guard = array_get($exception->guard(),0);
switch ($guard) {
case 'admin':
return redirect()->guest(route('admin.login'));
break;
default:
return redirect()->guest(route('login'));
break;
}
这是我的config/auth的内容:
<?php
return [
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
],
'admins' => [
'provider' => 'admins',
'table' => 'password_resets',
'expire' => 60,
],
],
];
我已经启用了多授权系统,我有一个管理员登录名和一个用户登录名,我不想在我的用户页面注册后禁用登录。
在异常中检查守卫可以这样做:
return redirect(route(auth()->guard('admin')->check() ? 'admin.login' : 'login'));
此外,如果您试图重写方法,请在 RegisterController@register
中使用 auth()
帮助程序或 Auth::
外观:
auth()->guard('admin')->login($user);