Sunday, March 5, 2017

Laravel - ServiceProvider : Give me Error 500

After adding a ServiceProvider, Laravel give me an Error 500... If I remove the :

app.php :

// ...
'providers' => [
   // ...
   \App\Providers\Game\GameServiceProvider::class,
 ],
// ...

The error no longer exist, thats how I know he is the one.

GameServiceProvider :

namespace App\Providers\Game;

use Illuminate\Support\ServiceProvider;

class GameServiceProvider extends ServiceProvider
{

    protected $defer = true;

    public function register()
    {
        $this->app->bind(StdGameRepository::class, function() {
            return new StdGameRepository();
        });

        $this->app->bind(GameRepositoryInterface::class, StdGameRepository::class);
    }

    public function provides()
    {
        // dd($this->app->make(StdGameRepository::class)); // Show nothing
        return [GameRepositoryInterface::class];
    }
}

I know, there's no need of binding because there's no DI, I am experiencing...

GameRepositoryInterface :

namespace App\Providers\Game;

interface GameRepositoryInterface
{
    public function getLastAdd();
}

StdGameRepository :

namespace App\Providers\Game;

class StdGameRepository implements GameRepositoryInterface
{
    private $lastAdd;

    public function __construct()
    {
        $this->lastAdd = "Testing";
    }

    public function getLastAdd()
    {
        return $this->lastAdd;
    }
}



via Thomas Petillot

Advertisement