1

I want to use same route in 2 scenarios,

  1. use route without passing parameter
  2. use route with parameter

So, is it possible & how to do it?

2

2 Answers 2

3
You can optional parameters like this

Route::get('my-method/{param?}', function ($param= null) {
// your code here
});
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.