jelovac / bitly4laravel

Provides a Laravel package to communicate with Bit.ly API
35 stars 18 forks source link

Service container problem in L5 #34

Closed alberto-bottarini closed 6 years ago

alberto-bottarini commented 7 years ago

I got this error:

Class bitly4laravel does not exist

Investigating, i discovered that in L4ServiceProvider, Bitly4Laravel service is registered using bitly4laravel as $key

    $this->app['bitly4laravel'] = $this->app->share(function ($app) {
        $config = $app['config']->get('bitly4laravel::config');
        return new Bitly4laravel($config);
    });

while in L5ServiceProvider it use a different $key, the complete name of the class:

    $this->app->singleton(Bitly4laravel::class, function($app) {
        $config = $app['config']['bitly4laravel'];
        return new Bitly4laravel($config);
    });

Changing with $this->app->singleton('bitly4laravel', function($app) {, it works

jelovac commented 7 years ago

Hi @alberto-bottarini,

You experience this on Laravel 5? The Laravel4ServiceProvider is used for Laravel 4 and it shouldn't be taken into account on Laravel 5.

If that is the case than there is probably an issue with this method:

private function getProvider()
{
    $app = $this->app;
    $version = intval($app::VERSION);
    $provider = sprintf('\Jelovac\Bitly4laravel\Laravel%dServiceProvider', $version);
    return new $provider($app);
}

I will test it.

mbarwick83 commented 7 years ago

I'm getting same error. Any update? I'm running 5.4

mbarwick83 commented 7 years ago

Scratch that. It's been a while since I did a composer update. I see the ServiceProviders changed. I should be using Jelovac\Bitly4laravel\laravel5ServiceProvider::class. You should prob update the README :)

mbarwick83 commented 7 years ago

FACADE is not working though...