Adding a hash in the back URL when validating with

2019-08-02 15:07发布

问题:

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)

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

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

Thanks

回答1:

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

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

    ...
}


标签: php laravel-5