How to return back twice in Laravel?

前端 未结 2 2064
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 15:09

In Laravel, there is a function return back();, which returns the user to the previous page. Is it possible to return back(); more than once within

相关标签:
2条回答
  • 2020-11-28 15:16

    it works for me Redirect::to($request->request->get('http_referrer'))

    0 讨论(0)
  • 2020-11-28 15:23

    No, but you could use session system to save URLs of 2-3-4 pages back. Use Session:: facade or session() helper for shorter syntax:

    $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
    

    And to use it:

    return redirect(session('links')[2]); // Will redirect 2 links back
    
    0 讨论(0)
提交回复
热议问题