I have a edit button: <a href={{ route('edit-category',$category->id) }} >Edit</a> which redirects me to a page where I can edit a category using its ID.
The problem I have is that I am using pagination to view only 5 categories per page and when I am on the edit page I have a Go Back back button which should redirect me back to viewing category. Now the issue is after a few refresh on the edit category page, url()->previous() does not work as intended. Instead of returning back to View Categories it just refreshes and stay on the same page.
I have tried url()->previous(), URL::previous(), JS's history.back() and they all give me the same results which in my case is not what I want to do because as soon as you update a category, the back button will return you back to the same edit page.
Any Idea how I can solve this issue?
Here's my current code...
The button that redirects to the edit page: <a href="{{ route('edit-category',$category->id) }}" >Edit</a>
The route on my CategoryController in web.php Route::get('/edit-category/{id}',[CategoryController::class,'edit'])->name('edit-category');
The button that should be redirecting me back to View Categories: <a href="{{ url()->previous() }}" ><i >arrow_back</i> View Categories</a>
CodePudding user response:
I had somewhat of a similar issue and solved it by using this:
return redirect()->back();
However it is hard to tell you anything specific since you did not post any code.
CodePudding user response:
Not sure what exactly is your situation but you can try the following code as you already know the exact webpage to go with the right parameter :
Route::get('/view-category/{id}',[CategoryController::class,'view'])->name('view-category')
{{ route('view-category',[id]) }}
