我正在尝试在 laravel 中实现一个干净的架构,因此我将自己的代码移动到一个src
文件夹中。
我的控制器位于src\notebook\infrastructure
但当我以routes\web.php
这种方式调用它时:
Route::get('/notebook', 'src\notebook\infrastructure\NotebooksController@show');
我收到了这个错误:
Illuminate\Contracts\Container\BindingResolutionException
Target class [src\notebook\infrastructure\NotebooksController] does not exist.
http://127.0.0.1:8000/notebook
我还更改了类中的命名空间值RouteServiceProvider
:
protected $namespace = 'App\Http\Controllers';
至
protected $namespace = '';
这是我的笔记本控制器类:
namespace src\notebook\infrastructure;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class NotebooksController extends Controller
{
public function show($id)
{
echo 'controller from infrastructure folder';
}
}
我的 laravel 和 php 版本composer.json
是:
"php": "^7.2.5",
"laravel/framework": "^7.24",
我觉得我错过了一些愚蠢的东西,但不知道是什么。