I have a form that includes tabs of different data. The tabs are activated by query string. After saving the content of the form that was submitted, I need to redirect back to it to show the corresponding tab using the query data. How can that be done?
currently I am using this for redirection:
return Redirect::back()->withErrors($validation);
but this returns to the first tab even there were no changes made on that tab. I saw something like
return Redirect::back()->withErrors($validation)->withQuery('tab'=>'info');
but that didn't work. Any suggestions?
A Query String Collection is used to retrieve the variable values in the HTTP query string. If we want to transfer a large amount of data then we can't use the Request. QueryString. Query Strings are also generated by form submission or can be used by a user typing a query into the address bar of the browsers.
Redirect to a Controller Action The last piece of the puzzle is that you can redirect to a specific Method of a specific Controller, no matter what its Route or URL is – use method action(): return redirect()->action('App\Http\Controllers\BooksController@index');
If you're using Redirect::to()
then is simple.
return Redirect::to('route_name?q='.$append_data)
If you want to use Redirect::back()
then do these following
# Pass the value while redirecting
return Redirect::back()->with('query_data', 'some_data');
And add condition to your blade file.
@if(!empty(Session::get('query_data')) && Session::get('query_data') == 'some_data')
<script>
$(function() {
//Change the tab using javascript or
//use location.href to refresh after appending query params to url.
});
</script>
@endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With