Laravel redirect route with query string example

We may require to redirect the named route with another parameter or query string in the laravel application, you can do it simply by using the “redirect()” helper. redirect() helper provides method route for redirect named route.

In this example I will show you how to redirect simply named route, redirect with named route and params, redirect with named route with the message. You can simply use and understand.

So here, let’s see how you can redirect route in your controller method:

Redirect to Named Route

public function show(){    
  return redirect()->route('home');
}

Redirect to Named Route with parameters

public function show(){    
  return redirect()->route('item.view',['id'=>2]);
}

Redirect to Named Route with query string

public function show(){    
  return redirect()->route('home')->with('message','I am back to home page.');
}

As the above example, you can simply return redirect using route name, you can also do it using URL, but I will put article soon for that.

You May Also Like

About the Author: Sumanta Kabiraj

Leave a Reply

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