Add an anchor to Laravel redirect back

11,684

Solution 1

return Redirect::to(URL::previous() . "#whatever");

And remember to import it at the top:

use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\URL;

I hope this works for you!

Solution 2

You can use these helpers for laravel 5.5 and above - no imports :-)

return redirect()->to(url()->previous() . '#hash');
Share:
11,684
user32421
Author by

user32421

Updated on June 11, 2022

Comments

  • user32421
    user32421 almost 2 years

    In a Laravel controller I have this redirect:

        return redirect()->back();
    

    Which returns me to my previous page (say http://domain/page). However, I want to make the page jump to a particular anchor (say #section). So ultimately this page should be opened: http://domain/page#section. How can I make this happen? I tried appending the anchor to the redirect but that doesn't work.