Laravel cannot find class of a package

2019-08-03 06:01发布

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

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

<?php namespace Cycs\Proofhq;

class Proofhq {

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

/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';
    }

}

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();
});

But I get the following error,

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?

1条回答
forever°为你锁心
2楼-- · 2019-08-03 06:22

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

查看更多
登录 后发表回答