使用自定义请求进行验证时,在后URL中添加哈希 [英] Adding a hash in the back URL when validating with custom request

查看:51
本文介绍了使用自定义请求进行验证时,在后URL中添加哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在验证Laravel中的表单,定义如下:

I'm validating a form in Laravel, defined like this:

class ContactFormRequest extends Request
{ ... }

在我的控制器中,我有:

And in my controller I have:

public function contact_form(ContactFormRequest $request)

,一切都很好.该请求将验证并返回错误的Request::back();.

and everything is just fine. The request validates and returns to Request::back(); with the errors.

如何向后URL添加哈希,例如/contact_form#hash?

How can I add a hash to the back URL, like /contact_form#hash?

谢谢

推荐答案

找到了它. 在自定义请求的构造函数中添加:

Found it. In the constructor of the custom request add:

class ContactFormRequest extends Request
{
    public function __construct()
    {
        $this->redirect = URL::previous().'#custom_hash';
    }

    ...
}

这篇关于使用自定义请求进行验证时,在后URL中添加哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆