N
N
NDll2020-07-29 14:07:28
Laravel
NDll, 2020-07-29 14:07:28

Bind model to repository in Laravel?

in the service provider, I connected the interface with the repository and the model

public function register()
    {
        $this->app->singleton(UserRepositoryContract::class, function () {
            $repository = new UserReporitory(
                new User()
            );
            return new $repository;
        });
    }

how to use this model in the repository now?
class UserRepository implements UserRepositoryContract
{
    private $model;

    public function __construct($user)
    {
        $this->model = $user;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmitriy, 2020-07-29
@NDll

you take everything correctly and you use getting data through $this->model
by implementing the UserRepositoryContract
contract it would be nice to see

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question