jeudi 28 avril 2016

Laravel Repository pattern and many to many relation

In our new project we decided to use hexagonal architecture. We decided to use repository pattern to gain more data access abstraction. We are using command bus pattern as service layer. In our dashboard page we need a lot of data and because of that we should use 3 level many to many relations (user -> projects -> skills -> review) and also skills should be active(status=1).

The problem rises here, where should i put this?

  1. $userRepository->getDashboardData($userId).

2.$userRepository->getUser($userId)->withProjects()->withActiveSkills()->withReviews();

3.$user = $userRepository->getById(); $projects = $projectRepository->getByUserId($user->id); $skills = $skillRepository->getActiveSkillsByProjectsIds($projectIds);

In this case, I couldn't find the benefits of repository pattern except coding to interface which can be achived with model interfac. I think solution 3 is prefect but it adds a lot of work.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire