I want to call a route function from my controller with some parameters.
This is my Controller
public function myFunction($id, $name)
{
$id = 1;
$name = 'john';
return redirect()->route('details/' . $id . '/' . $name);
}
This is my route
Route::get('details/{id}/{name}',['uses' =>'My_controller@myFunction']);
This is the error I get when I run the script.
InvalidArgumentException in UrlGenerator.php line 304:
Route [details/1/john] not defined.
Please Help
route() helper requires you to pass route name and parameters:
function route($name, $parameters = [], $absolute = true)
{
return app('url')->route($name, $parameters, $absolute);
}
So you need to give your route a name:
Route::get('details/{id}/{name}',['uses' =>'My_controller@myFunction'])->name('details');
..and then you can pass parameters in an array:
return redirect()->route('details', array('id' => $id, 'name' => $name));
Hope this helps
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