I guess this will help you decide https://www.youtube.com/watch?v=dfgtKb-VpRk
Where to store some functions ? In the models or inside a dedicated repository ?
I have used now Laravel for a couple of weeks and I have a doubt about something.
I use the repository pattern for accessing data in the DB so that I have an extra layer. Mainly the concerned functions are "store", "all", "get", etc. However, sometimes when I create a new function, I'm asking myself where should I put this function : inside the model or inside the dedicated repository ?
For example : let's say I want to manage devices. Then, I have a file for the model, another for the Controller and eventually a repository called DeviceRepository.
In my repository, I put all the functions that is managing the CRUD part (All, Get, store...).
Now, let's say I want to retrieve all the records (a table that have a device foreign key) that are associated to the device.
Let's call this function getRecords().
For me, the most intuitive way to do that is to put this function inside the model Device. So that, I can do myDevice->getRecords()
However, I still wonder if I should instead put this function inside the dedicated repository.
For example, I would write instead myDeviceRep->getRecords($deviceId)
What do you think ? What are the best practices ? What do you recommend to me ?
Thank a lot
Please or to participate in this conversation.