N
N
Northern Lights2019-11-12 17:48:43
Laravel
Northern Lights, 2019-11-12 17:48:43

How can I get an instance of the repository?

Hello members!
Tell me, how can I get an instance of an arbitrary repository from an arbitrary class, as if we received it using injection from a service container?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Wells, 2019-11-13
@php666

As far as I understand, the author needs to get the dependency inside the object that was not created through the container (and the dependencies are not injected, respectively). If so then:

public function __construct()
{
    $this->userRepository = resolve(UserRepository::class);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question