这个路由要怎么写
/{model}/lists 转发到{$model}Controller控制器的lists方法
如 /shop/lists => shopController控制器 lists方法,
/user/lists => userController控制器 lists方法,
不能手动一个个写 我有好多model啊
<code class="text">Route::get('{model}/lists', function ($model) {
$className = 'AppHttpControllers\'.ucfirst($model).'Controller';
$obj = new $className;
return $obj->lists();
});
</code><code class="php"><span class="x">Route::group(['prefix' => 'shop'], function() {</span>
<span class="x"> Route::get('list', 'ShopController@list');</span>
<span class="x">})</span>
</code>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号