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
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.
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