Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.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 参数为laravel 5.2的路线_Php_Laravel_Routes - Fatal编程技术网

Php 参数为laravel 5.2的路线

Php 参数为laravel 5.2的路线,php,laravel,routes,Php,Laravel,Routes,我被描述为routes.php Route::get('/{id}', 'HomeController@index'); 我想使用没有参数的HomeController。怎么做 更新: 如果url没有参数,我还想使用HomeController显示主页,如果url有参数,我想使用controller显示一些数据。您的id将作为参数传递给控制器函数 public function index($id) { echo $id; } 如果要在没有参数的情况下使用它,则需要一个可选参数 Route

我被描述为routes.php

Route::get('/{id}', 'HomeController@index');
我想使用没有参数的HomeController。怎么做

更新:
如果url没有参数,我还想使用HomeController显示主页,如果url有参数,我想使用controller显示一些数据。

您的id将作为参数传递给控制器函数

public function index($id) {
echo $id;

}
如果要在没有参数的情况下使用它,则需要一个可选参数

Route::get('/{id?}', 'HomeController@index');
将控制器功能更改为

public function index($id = 0) {
    if ($id > 0 ) {
    echo $id;
    } else {
     echo "display all";
    }
    }

您的id将作为参数传递给控制器函数

public function index($id) {
echo $id;

}
如果要在没有参数的情况下使用它,则需要一个可选参数

Route::get('/{id?}', 'HomeController@index');
将控制器功能更改为

public function index($id = 0) {
    if ($id > 0 ) {
    echo $id;
    } else {
     echo "display all";
    }
    }
您要使用:

有时您可能需要指定管线参数,但该管线参数的存在是可选的。您可以通过放置?在参数名称后标记

您要使用:

有时您可能需要指定管线参数,但该管线参数的存在是可选的。您可以通过放置?在参数名称后标记


我知道,但我也想不带param使用这条路线。我知道,但我也想不带param使用这条路线。