Have a UI that has some tabbed content. A tab can be specified to be active (displayed) by using a URL parameter.
The use case is as follows:
Users loads page. (i.e. foo.com/mypage)
Clicks on the tab where they need to add a note.
Submits and the note is created.
Routes back()->with('success', 'blah')
The problem I'm having is that I'd prefer to route back() to the page after creating a note, but include a URL parameter so the tab the user was just working in is automatically displayed and they can see their note. (i.e. foo.com/mypage?tab=notes). Is that possible or must one route('my.route.path', ['tab' => 'notes']) like this?
I've looked through documentation and perhaps I'm just missing something simple. Or am I approaching this seemingly simple issue incorrectly?
One solution to this problem is to use the redirect() method instead of back(). You can pass the URL with the desired parameter as an argument to the redirect() method. Here's an example:
This code will redirect the user back to the previous page with the tab parameter set to notes. The with() method is used to flash a success message to the session.
Note that url()->previous() will return the URL of the previous page, so this code will work even if the user came to the current page from a different URL.