Laravel redirect route with query string example


We may require to redirect named route with another parameters or query string in laravel application, you can do it simply by using "redirect()" helper. redirect() helper provide method route for redirect named route. In this example i will show you how to redirect simple named route, redirect with named route and params, redirect with named route with message. You can simple 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 above example you can simple return redirect using route name, you can also do it using url, but i will put article soon for that.


April 28, 2017 | 1316 Viewer | Category : Laravel

Related Posts: