John Davidson

php - How can i call route from laravel controller?

0 comments
Message:


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 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us