【发布时间】:2016-04-25 12:12:23
【问题描述】:
创建了以下文件:
文件:App\Services\Custom\Auth\AuthService.php
名称空间:App\Services\Custom\Auth
类名:AuthCustom
内部方法:foo()
在我的控制器中,我试图从我创建的服务中调用 foo 方法。
App\Services\Custom\Auth\AuthService\AuthCustom::foo()
为什么一直返回Class 'App\Services\Custom\Auth\Authservice\AuthCustom' not found
我做错了什么?
谢谢!!
编辑: 我在 composer.json 中添加了这个并运行 composer dump-autoload 没有错误。 它有效!
"autoload": {
"classmap": [
"database",
"app/Services/Custom/Auth/AuthService.php"
],
"psr-4": {
"App\\": "app/"
}
},
【问题讨论】:
-
您的 composer.json 中是否有将
App\Custom\Auth映射到App\Services\Custom\Auth的内容?没有它,您的命名空间中将缺少Services -
我尝试在提供程序中添加 App\Services\Custom\Auth\AuthService::class 但不起作用
-
我认为问题在于它不是 ServiceProvider 吗?
标签: php class laravel namespaces