[英]Class 'Vendor\PackageName\ClassName' not found for newly created Laravel package
I've a problem running my newly created Laravel package which please check out https://github.com/Younesi/laravel-aparat 我在运行新创建的Laravel软件包时遇到问题,请查看https://github.com/Younesi/laravel-aparat
I can download it via Composer with no problem and it's auto-discovered via Laravel but when I try to use it, It gives me the following error of not finding class. 我可以毫无问题地通过Composer下载它,并且可以通过Laravel自动发现它,但是当我尝试使用它时,出现了以下找不到类的错误。
Class 'Younesi\\LaravelAparat\\Aparat' not found
找不到类'Younesi \\ LaravelAparat \\ Aparat'
My service Provider code is like: 我的服务提供商代码如下:
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->bind('aparat', function ($app) {
return new Aparat;
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('aparat');
}
Any help would be appreciated. 任何帮助,将不胜感激。
Looking at the package it's working fine, in composer.json
of that package there is: 查看该程序包,它工作正常,在该程序包的
composer.json
中有:
"autoload": {
"psr-4": {
"Younesi\\laravelAparat\\": "src"
}
},
Notice that laravel
is not with capital letter here, so in your code you should import rather this way: 请注意,
laravel
在此处不带有大写字母,因此在代码中,您应该这样导入:
use Younesi\laravelAparat\Aparat;
instead of: 代替:
use Younesi\LaravelAparat\Aparat;
I also see that you are author of this package, so I would recommend using standard conversion (namespace starting with capital letter) instead of current namespace. 我还看到您是此程序包的作者,所以我建议您使用标准转换(以大写字母开头的命名空间)代替当前的命名空间。
Looking further at package code, I also see that in service provider there is: 进一步查看程序包代码,我还看到在服务提供商中有:
namespace Younesi\LaravelAparat;
namespace so it's nothing weird it won't work if you autoload it with lower-case letter and have namespace with upper-case letter 命名空间,所以如果您用小写字母自动加载命名空间并使用大写字母命名空间,它就不会起作用
There were some cases with registration problem, cache issues, etc. Try one of these solutions: 在某些情况下会出现注册问题,缓存问题等。请尝试以下解决方案之一:
composer dump-autoload
composer dump-autoload
composer init
composer init
php artisan config:cache
or delete everything in bootstrap/cache/
php artisan config:cache
或删除bootstrap/cache/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.