Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在路由中使用可选参数_Php_Laravel - Fatal编程技术网

Php 在路由中使用可选参数

Php 在路由中使用可选参数,php,laravel,Php,Laravel,我想在两个场景中使用相同的路线 使用不传递参数的路由 使用带有参数的路由 那么,这有可能吗&如何做到呢?在Web Php中 You can optional parameters like this Route::get('my-method/{param?}', function ($param= null) { // your code here }); Route::get('find-services/{service_name?}', 'commonController@find_

我想在两个场景中使用相同的路线

  • 使用不传递参数的路由
  • 使用带有参数的路由
  • 那么,这有可能吗&如何做到呢?

    在Web Php中

    You can optional parameters like this
    
    Route::get('my-method/{param?}', function ($param= null) {
    // your code here
    });
    
    Route::get('find-services/{service_name?}', 'commonController@find_services')->name('find-services');
    
    并在commonController.php中处理参数

    public function find_services($service_name = null) {// Do something here}
    
    或使用get方法检查控制器中的参数

    public function find_services() {
        $input = Request::all();
        if (isset($input['service_name']) AND ! empty($_GET['service_name'])) {
            // Code
        }
    }
    
    我希望这篇文章能有所帮助,如需有关Web Php的更多信息,请点击这里=>

    Route::get('find-services/{service_name?}', 'commonController@find_services')->name('find-services');
    
    并在commonController.php中处理参数

    public function find_services($service_name = null) {// Do something here}
    
    或使用get方法检查控制器中的参数

    public function find_services() {
        $input = Request::all();
        if (isset($input['service_name']) AND ! empty($_GET['service_name'])) {
            // Code
        }
    }
    

    我希望这一条有帮助,有关更多信息,请参见这里=>

    是的,使用get方法是的,使用get方法