Laravel 5 Custom ServiceProvider not found

3.9k views Asked by At

I'm making a Laravel ServiceProvider for a package. The package is https://github.com/sumocoders/Teamleader

I get the following error

FatalErrorException in ProviderRepository.php line 150: Class 'Notflip\Teamleader\TeamleaderServiceProvider' not found

I have no clue what I'm doing wrong, Here's my folder structure

enter image description here

composer.json in my package

"autoload": {
    "psr-4": {
       "Notflip\\Teamleader": "src/"
    }
}

TeamleaderServiceProvider

<?php namespace Teamleader\Laravel;

use Illuminate\Support\ServiceProvider;

class TeamleaderServiceProvider extends ServiceProvider
{
    /**
     * Register bindings in the container.
     *
     * @return void
     */
    public function publishes()
    {
        $this->publishes([
            __DIR__.'/Config/config.php' => config_path('teamleader.php'),
        ]);
    }
    public function register()
    {
        $this->app->bind('Teamleader\Laravel', function () {
            return new Teamleader(config('teamleader.API_GROUP'), config('teamleader.API_SECRET'), config('teamleader.SSL'));
        });
    }
}

Facade

<?php namespace Teamleader\Laravel\Facade;

class Teamleader extends Facade
{
    protected static function getFacadeAccessor()
    {
        return 'Teamleader';
    }
}

In my config.php I added the following line to the providers

'Notflip\Teamleader\TeamleaderServiceProvider',

And this line to the aliasses

'Teamleader'=> 'Notflip\Teamleader\Facade\Teamleader'

Anyone has any idea what I might be doing wrong? Thank you! I'm so close to the result!

2

There are 2 answers

3
Styphon On

Your definition in composer is missing the initial slashes and you haven't specified the path to src from root.

"psr-4": {
   "\\Notflip\\Teamleader": "notflip/teamleader-laravel/src/"
}

Also your declaration of the name space at the top of TeamleaderServiceProvider is wrong, it should be:

<?php namespace Notflip\Teamleader;
0
Miguel Stevens On

Solved

In the facade, the IOC binding was named wrong ( wrong case )

The name should have been 'teamleader' in lowercase.

Facade

class Teamleader extends Facade
{
    protected static function getFacadeAccessor()
    {
        return 'teamleader';
    }
}

Service Provider

<?php namespace Teamleader\Laravel;

use Illuminate\Support\ServiceProvider;

class TeamleaderServiceProvider extends ServiceProvider
{
    /**
     * Register bindings in the container.
     *
     * @return void
     */
    public function publishes()
    {
        $this->publishes([
            __DIR__.'/Config/config.php' => config_path('teamleader.php'),
        ]);
    }
    public function register()
    {
        $this->app->bind('teamleader', function () {
            return new Teamleader(config('teamleader.API_GROUP'), config('teamleader.API_SECRET'), config('teamleader.SSL'));
        });
    }
}