Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add an anchor to Laravel redirect back

Tags:

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.

like image 288
user32421 Avatar asked Oct 03 '16 20:10

user32421


1 Answers

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!

like image 182
FluxCoder Avatar answered Nov 06 '22 01:11

FluxCoder