laravel登录验证跳转
时间: 2023-10-12 13:05:03 浏览: 33
Laravel 的登录验证跳转可以通过设置 `redirectTo` 属性来实现。在 `app/Http/Controllers/Auth/LoginController.php` 中,可以找到以下代码:
```php
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
```
`$redirectTo` 属性指定了登录成功后需要跳转的页面。你可以将其修改为你需要跳转的页面,例如:
```php
protected $redirectTo = '/dashboard';
```
在这个例子中,登录成功后将跳转到 `/dashboard` 页面。
如果你需要在用户登录失败时跳转到不同的页面,可以在 `LoginController` 中重写 `showLoginForm` 和 `sendFailedLoginResponse` 方法:
```php
/**
* Show the application's login form.
*
* @return \Illuminate\View\View
*/
public function showLoginForm()
{
return view('auth.login', ['url' => '/dashboard']);
}
/**
* Get the failed login response instance.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Illuminate\Validation\ValidationException
*/
protected function sendFailedLoginResponse(Request $request)
{
throw ValidationException::withMessages([
$this->username() => [trans('auth.failed')],
])->redirectTo('/login');
}
```
在这个例子中,登录失败后将跳转到 `/login` 页面。你可以将其修改为你需要跳转的页面。