How to add hash (#) to a route redirect in Laravel

Categorized as Laravel

If you want to use redirect to a specific section on a page, you might want to use withFragment(), so you can use the fragment of the URI:

return redirect()->route('test.route')->withFragment('example-section');

You can also utilize this method when redirecting upon form completion:

return redirect()->to(url()->previous())->withFragment('example-section');

Via @ecrmnn

Leave a reply

Your email address will not be published. Required fields are marked *