Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

newbieprogrammer's avatar

Laravel how to redirect second last page

Hi guys, i'm trying go back to second last page after updating data from my another view how can i do that?

0 likes
3 replies
newbieprogrammer's avatar

Actually i saw some answers from others source like

$links = session()->has('links') ? session('links') : [];
$currentLink = request()->path(); // Getting current URI like 'category/books/'
array_unshift($links, $currentLink); // Putting it in the beginning of links array
session(['links' => $links]); // Saving links array to the session

but i really don't know where should i put the code :(

chaudigv's avatar

If you are certain that after updating you are suppose to go to a fixed view irrespective of the what the second last page could be, then a basic redirect('/list') would suffice.

newbieprogrammer's avatar

Hi, the page is not fixed actually it can be open from different view. For example, i filter the invoice using daterange then after updating i want go back to /invoice/daterange/from-to not /invoice. l

Please or to participate in this conversation.