在最近的 Laravel(可能是 v8 或更高版本)中,如果你在初始状态下在 routes/web.php 中编写以下代码,你将无法找到应该在那里的 Controller Class,并且会出现错误。
Route::get('/hoge', 'Controller@index');
Illuminate\Contracts\Container\BindingResolutionException Target class [Controller] does not exist. http://laravel.internal/hoge Illuminate\Container\Container::build htdocs\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php:811
显然,我开始忘记了 Contoller 的初始位置。
一致
$namespace
取消注释App / Providers / RouteServiceProvider.php
/** * The controller namespace for the application. * * When present, controller route declarations will automatically be prefixed with this namespace. * @var string|null */ protected $namespace = 'App\\Http\\Controllers'; //