Laravel找不到包的类 [英] Laravel cannot find class of a package

查看:609
本文介绍了Laravel找不到包的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我为我正在研究的Laravel项目创建了一个新的Package,对于Packages和laravel本身是一个新概念,但这是我想出的代码,

Hello I have created a new Package for a Laravel project I am working on, I am new to the concept of packages and laravel itself, but here is the code I have come up with,

/workbench/cycs/proofhq/src/Cycs/Proofhq/ProofhqServiceProvider.php

/workbench/cycs/proofhq/src/Cycs/Proofhq/ProofhqServiceProvider.php

public function boot()
{
    $this->package('cycs/proofhq');
}

/**
 * Register the service provider.
 *
 * @return void
 */
public function register()
{
    $this->app->booting(function()
    {
        $loader = \Illuminate\Foundation\AliasLoader::getInstance();
        $loader->alias('Cycs', 'Cycs\Proofhq\Facades\Supyo');
    });

    $this->app['proofhq'] = $this->app->share(function($app)
    {
        return new Proofhq;
    });
}

/workbench/cycs/proofhq/src/Cycs/Proofhq/Proofhq.php

/workbench/cycs/proofhq/src/Cycs/Proofhq/Proofhq.php

<?php namespace Cycs\Proofhq;

class Proofhq {

    public static function greeting() {
        return "What's up dawg!";
    }
}

/workbench/cycs/proofhq/src/Cycs/Proofhq/Facades/Proofhq.php

/workbench/cycs/proofhq/src/Cycs/Proofhq/Facades/Proofhq.php

<?php namespace Cycs\Proofhq\Facades;

use Illuminate\Support\Facades\Facade;

class Proofhq extends Facade {

    /**
    * Get the registered name of the component.
    *
    * @return string
    */

    protected static function getFacadeAccessor() {
        return 'proofhq';
    }

}

我已将软件包添加到app/config/app.php和providers数组中,然后尝试通过简单的get来访问软件包功能

I have added the package to the app/config/app.php and the providers array, then try to access the package functions via a simple get,

Route::get('/test', function(){
  echo proofhq::greeting();
});

但是出现以下错误

找不到类'proofhq'

Class 'proofhq' not found

我不知道为什么,我按照字母的示例进行操作,并且该类存在.

I cannot work out why, I have followed the examples to the letter, and the class exists.

有人可以帮我这个忙吗?

Can anyone shed anylight on this for me?

推荐答案

composer dump-autoload并将路由中的类名首字母更改为大写似乎可以解决问题!

composer dump-autoload and change the class name first letter in the routes to uppercase seems to do the trick!

这篇关于Laravel找不到包的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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