I want to call route from laravel controller function with parameter and option parameters.
$product_information = route('route', $parameter, '?optionalParameter');
My Answer:
You can call a route from a Laravel controller using the `redirect()` method. Here's an example of how you can do this:
php
use Illuminate\Support\Facades\Redirect;
public function yourControllerFunction() {
$parameter = 'your_parameter_value';
$optionalParameter = 'your_optional_parameter_value';
$product_information = redirect()->route('route', ['parameter' => $parameter, 'optionalParameter' => $optionalParameter]);
return $product_information;
}
In this example, replace `'route'` with the name of the route you want to call, and `'your_parameter_value'` and `'your_optional_parameter_value'` with the actual values you want to pass as parameters. The `redirect()->route()` method will generate the URL for the specified route with the parameters included.
Rate this post
4 of 5 based on 3357 votesComments