Saturday, April 15, 2017

Repository and Services pattern laravel

I have a project built in laravel and we are using the repository pattern. But I am not sure if we get this right.

We have a Controller, that calls it service, for example, a UserController that calls a UserService.

The Service calls its repository and other services that are used. For example, UserService calling UserRepository and any other Service (QuestionService, CourseService, etc).

And we instantiate all the dependencies of this UserService on the __construct().

But we are causing some deadlocks, a UserService, calling any other service, that calls UserService too.

So I'd like to know if is this the right way to call a service and repositories in a laravel Project. What we are doing wrong? We should not instantiate the methods on the construct, or what else could it be.

Thanks.



via Victor Oliveira

Advertisement