I am new to Laravel. I am making an app to rate seasons of a TV show. I want to get the information for each season with the average rating and the current user's personal rating.
Currently I am just doing accessing it with raw MySQL.
$seasons = \DB::select('
SELECT * FROM seasons
LEFT JOIN (SELECT season_id, AVG(rating) as avg_rating FROM ratings_season
GROUP BY season_id) t2 ON seasons.id = t2.season_id
LEFT JOIN (SELECT season_id, rating FROM ratings_season WHERE user_id = 1) t3 ON seasons.id = t3.season_id
ORDER BY seasons.number DESC');
How can I convert this raw query to one using Laravel Relationships?