E
E
Ellik2018-02-23 14:56:27
Laravel
Ellik, 2018-02-23 14:56:27

Why doesn't binding an interface to a class work in a ServiceProvider?

I use this binding
$this->app->bind(BoardRepository::class, EloquentBoardRepository::class);
But passing the BoardRepository $boardRepository parameter in the controller does not cause any errors. I remove the parameter and everything is ok. Tell me, please, what could be wrong. I fight already the second day.

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use App\Repositories\Contracts\BoardRepository;
use App\Repositories\EloquentBoardRepository;

class RepositoriesServiceProvider extends ServiceProvider
{
    protected $defer = true;

    public function register()
    {
        $this->app->bind(BoardRepository::class, EloquentBoardRepository::class);
        // $this->app->bind(NoteRepository::class, EloquentNoteRepository::class);
    }

    public function provides()
    {
        return [
            BoardRepository::class,
            // NoteRepository::class,
        ];
    }
}

public function __construct(BoardRepository $boardRepository)
{
    dd($boardRepository);
    //$this->boardsRepository = $boardsRepository;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2018-02-23
@JhaoDa

Problem in . Either remove it or remove it from the cache so that it is regenerated. protected $defer = true;services.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question