Reputation: 155
I want to use same route in 2 scenarios,
So, is it possible & how to do it?
Upvotes: 1
Views: 117
Reputation: 831
In Web Php
Route::get('find-services/{service_name?}', 'commonController@find_services')->name('find-services');
and handle the parameters in commonController.php
public function find_services($service_name = null) {// Do something here}
Or Simple use the get method and check parameter in Controller
public function find_services() {
$input = Request::all();
if (isset($input['service_name']) AND ! empty($_GET['service_name'])) {
// Code
}
}
I hope this one helps and For More Information Here => https://laravel.com/docs/7.x/routing#parameters-optional-parameters
Upvotes: 1
Reputation: 807
You can optional parameters like this
Route::get('my-method/{param?}', function ($param= null) {
// your code here
});
Upvotes: 3