Reputation: 1653
I am currently working on eloquent models, and I have a model TheSeries
and I would like to display similar series based on TheGenres
model.
In your opinion, where this should be done between controller or model in Laravel?
Can you help give me an example of code, so I can understand how to return similiar series based on genreID/genreName from TheGenres
model. Thanks.
I need same query but in Laravel\Eloquent way:
SELECT m2.* FROM mSeriesGenres m1
INNER JOIN mSeriesGenres m2
ON m1.genreID = m2.genreID
JOIN TheSeries m3
ON m3.id = m1.seriesID
WHERE m1.seriesID = 13 AND m2.seriesID <> 13
GROUP BY m2.seriesID HAVING COUNT(*) = (SELECT COUNT(*) FROM mSeriesGenres WHERE seriesID = 13)
I would like to point out that mSeriesGenres is the many-to-many table.
Upvotes: 4
Views: 311
Reputation: 12574
You can try a repository pattern approach:
https://bosnadev.com/2015/03/07/using-repository-pattern-in-laravel-5/
Upvotes: 1