比如controller有个函数是
public function test($var) { //some code... }
怎样在routes.php定义get/abc时调用Controller的test('abc')?
不用泛变量如Route::get(/{var}', function($var)...这样的形式,因为$var的值是固定的几个。
比如controller有个函数是
public function test($var) { //some code... }
怎样在routes.php定义get/abc时调用Controller的test('abc')?
不用泛变量如Route::get(/{var}', function($var)...这样的形式,因为$var的值是固定的几个。
Route::get('/{var}',function($var){ return $var; })->where('var','a|b|c|d|e|f|g');
Request对象也可以获取。
// URL: /portal/orders/2 public function _test(Request $request) { // 1: portal // 2: orders // 3: 2 return Request::segment(1); }
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号