Laravel - How to redirect with hash (#)

后端 未结 3 907
谎友^
谎友^ 2021-02-03 10:43

I have link :

example.com/register#register

If validation fails laravel redirects to :

example.com/register

w

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-03 10:59

    But if you want to get the proper URL where hash is the fragment part and not a parameter you should use:

    redirect(route('route_name', ['some_param_for_route']). '#hash')
    

    instead of:

    redirect()->route('route_name', [ 'some_param_for_route', '#hash' ])
    

    so to get:

    http://example.com/some_param_for_route#hash
    

    and not:

    http://example.com/some_param_for_route?#hash
    

    this way you can also chain it further like for instance:

    redirect(route('route_name', ['some_param']). '#hash')->with('status', 'Profile updated!');
    

提交回复
热议问题