请问我在 LoginRequest.php 中做错了什么,如果登录过程中出现任何错误,我在其中设置了重定向到自定义登录页面的条件?我的代码如下:
<?php namespace App\Http\Requests;
use App\Http\Requests\Request;
class LoginRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'login_email' => 'required',
'login_password' => 'required'
];
}
public function messages()
{
return [
'login_email.required' => 'Email cannot be blank',
'login_password.required' => 'Password cannot be blank'
];
}
public function redirect()
{
return redirect()->route('login');
}
}
如果有任何错误,该代码应该将从导航栏登录表单登录的用户重定向到主登录页面,但它似乎没有重定向。
最佳答案
如果你想重定向到一个特定的 url,那么使用 protected $redirect
class LoginRequest extends Request
{
protected $redirect = "/login#form1";
// ...
}
或者如果你想重定向到命名路由,则使用 $redirectRoute
class LoginRequest extends Request
{
protected $redirectRoute = "session.login";
// ...
}
关于php - 验证错误后的 Laravel 自定义重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30544779/