组(或回调)中的命名空间不起作用(Lumen、Laravel)?我想将代码从 routes.php 删除到 Controller 。所以!
use App\Http\Controllers;
// OK!
$app->get('path', 'BarController@getId');
$app->group(['prefix' => 'foo'], function ($app) {
// OK!
$app->get('path', '\App\Http\Controllers\BarController@getId');
// Class BarController does not exist
$app->get('path', 'BarController@getId');
});
最佳答案
为您 use
声明工作,你必须使用 ::class
句法:
use App\Http\Controllers\BarController;
$app->get('path', BarController::class.'@getId');
或者,您可以将命名空间添加到您的组中:
$app->group(['prefix' => 'foo', 'namespace' => 'App\Http\Controllers'], function ($app) {
$app->get('path', 'BarController@getId');
});
关于php - Laravel,带有前缀的路由中不存在类 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33170792/