skip to Main Content

I want to create a back button in any Blade file. What is the PHP syntax that will allow me to return to the previous page without redirecting?

In principle I do not know in advance the link of the previous page to do Redirect::route("/{previous-page}");.

I tried this Redirect::back() which doesn’t work, and I have to know the previous page to do Redirect::route("/{previous-page}");

Whereas href="/" has the consequence of entering the home page.

2

Answers


  1. Without redirect. Try this {{url()->previous()}} in your blade file where you want to put the back button.
    Here is an example with the boostrap button.

    <a class="btn btn-primary" href="{{url()->previous()}}"> Go Back </a>
    
    Login or Signup to reply.
  2. Sometimes {{url()->previous()}} will fails when we reloaded the page by placing the cursor in the url and press enter, window.history.back() will help you redirect to previous url

    <a class="btn btn-primary" onclick="window.history.back()">Back</a>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search