Laravel-作曲家无法找到服务提供商类 [英] Laravel - Composer unable to find the service provider class

查看:92
本文介绍了Laravel-作曲家无法找到服务提供商类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在创建 Laravel软件包(一种中间件).我的文件夹结构如下所示:

I have been creating a Laravel package (a Middleware). My folder structure looks like the following:

laravel-censor/
    config/
        sensor.php
    src/
        CensorMiddleware.php
        LaravelCensorServiceProvider.php
    composer.json

composer.json的内容是:

{
    "name": "kamranahmedse/laravel-censor",
    ...
    ...
    "require": {
        "php" : ">=5.4.0",
        "laravel/framework": "^5.1.11"
    },
    "autoload": {
        "psr-4": {
            "KamranAhmed\\LaravelCensor\\": "src/"
        }
    },
    "minimum-stability": "stable"
}

我已将其发布到 packagist ,可以通过

I have released it to packagist and can be found through github. Now after installing

composer require kamranahmedse/laravel-censor

当我将软件包的服务提供者添加到config/app.php

When I add the package's service provider to providers array in config/app.php

KamranAhmed\LaravelCensor\LaravelCensorServiceProvider::class

然后运行

php artisan vendor:publish

问题

它找不到服务提供者类,并引发未找到的类异常.任何人都可以指出我在这里做错了什么吗?为什么作曲家无法自动加载此类?

The problem

It is unable to find the service provider class and throws a class not found exception. Can any body please point out what am I doing wrong here? Why is composer not able to autoload this class?

我已经研究了一个多小时,无法弄清为什么作曲家没有自动加载此类的问题.另外,我检查了名称空间和类名称是否正确:

I have been looking into this for over an hour now and unable to figure out the problem that why composer isn't autoloading this class. Also, I have checked and the namespaces and class names are all correct:

# LaravelCensorServiceProvider.php
namespace KamranAhmed\LaravelCensor;
...
class LaravelCensorServiceProvider extends ServiceProvider
{ ... }

解决方案

事实证明,作曲家有一些缓存.清除作曲家缓存composer clear后运行php artisan clear-compiled可以解决问题.

Solution

It turned out that composer had some cache. Running php artisan clear-compiled after clearing the composer cache composer clear did the trick.

推荐答案

我可以安装您的软件包并执行php artisan vendor:publish而没有任何问题,您是否尝试过composer dumpautoload?和php artisan clear-compiled?

I could install your package and execute php artisan vendor:publish without any issues, have you tried composer dumpautoload? and php artisan clear-compiled?

这篇关于Laravel-作曲家无法找到服务提供商类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆