我正在验证Laravel中的一个表单,定义如下:
class ContactFormRequest extends Request
{ ... }
在我的控制器中,我有:
public function contact_form(ContactFormRequest $request)
一切都很好。该请求将验证并返回Request::back();
并显示错误。
如何在后面的网址中添加哈希值,例如/contact_form#hash
?
由于
答案 0 :(得分:1)
找到它。 在自定义请求的构造函数中添加:
class ContactFormRequest extends Request
{
public function __construct()
{
$this->redirect = URL::previous().'#custom_hash';
}
...
}
答案 1 :(得分:0)
我知道这是一个旧线程,但是,如果有任何搜索,我相信正确的方法是:
/**
* Get the URL to redirect to on a validation error.
*
* @return string
*/
protected function getRedirectUrl()
{
return parent::getRedirectUrl() . '#custom_hash';
}