How to Redirect a named route with query string in Laravel

How to Redirect a named route with query string in Laravel

In this post we will give you information about How to Redirect a named route with query string in Laravel. Hear we will give you detail about How to Redirect a named route with query string in LaravelAnd how to use it also give you demo for it if it is necessary.

Sometime you need to pass extra parameter as query string in Laravel route that is not part of a route parameters so don’t worry, you can pass everything as query string in route that is defined in route parameter.

Simple Redirect to Named Routes

return redirect()->route('dashboard');

Redirect named route with query string

  1. returnredirect()->route('dashboard',['product_id'=>1])
  2. ->with('message','Welcome to onlinecode.');
return redirect()->route('dashboard',['product_id'=>1])                ->with('message','Welcome to onlinecode.');

Here i am passing message variable as Flashed Session Data which you can use in your view to display message.

Redirect to Controller Action

You can also redirect to controller action, for this pass the controller name with action.

return redirect()->action('UserController@dashboard');

Redirect to another URL

 return redirect('user/dashboard');

Redirect responses are basically instances of the IlluminateHttpRedirectResponse class

Hope this code and post will helped you for implement How to Redirect a named route with query string in Laravel. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

8  +  2  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US