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.
Do you like below Tutorials ?
- PHP Laravel 5.5 - import export data into excel and csv using maatwebsite
- Laravel 7.x and 6.x create custom facade example from scratch
- Node JS - Get Real time online users counter using socket io example
- PHP Laravel 7.x and 6.x - Bootstrap Admin Theme Integration example from scratch
- MySQL Query - How to select records of today to next Sunday ?
- Laravel 7.x and 6.x - username custom validation example
- Laravel 5.5 - Import Extract zip file using chumper/zipper package
- PHP Laravel Set Custom Validation Error Messages Example