Open sidebar
// I have two tables: left: imagefolders with 24 rows right: conventionreports which might have more than one row with same imagefolder_id (imagegallery_id in my model!) public function scopeConventionGalleries($query) { $query->select('imagefolders.*', 'conventionreports.publicationdate') ->join('conventionreports', 'imagefolders.id', '=', 'conventionreports.imagegallery_id') ->where('imagefolders.is_conv_gallery', 1) ->with('conventionreport.image') ->orderBy('conventionreports.publicationdate', 'desc'); dd($query->toSql()); } // This leads to the following SQL "select `imagefolders`.*, `conventionreports`.`publicationdate` from `imagefolders` inner join `conventionreports` on `imagefolders`.`id` = `conventionreports`.`imagegallery_id` where `imagefolders`.`deleted_at` is null and `imagefolders`.`is_conv_gallery` = ? order by `conventionreports`.`publicationdate` desc" // Which produces 28 rows (so 4 imagefolders are shown doubled // What can I do to have only the 24 rows from image folders table, but with the first found publication date from the conventionreports table
Close sidebar
Back
Please note that all pasted data is publicly available.
Twitter
GitHub
Use setting
Back
Please note that all pasted data is publicly available.
Twitter
GitHub
Use setting