I have the following area in my eloquent model, and I want to add two conditions to it. I need help with this.
public function scopeImages($query) { $query->join('images as i', function ($join) { $join->on('i.vessel_id', '=', 'vessel.id') ->where('i.sort', '=', 'min(i.sort)'); }) ->leftjoin('users', 'users.id', '=', 'vessel.user_id') ->select('vessel.*', 'i.image as image', 'users.name as brokername'); }
Table
images
has featured
and sort
columns. I want to select one row where images.featured is 1
and min sort
returned results. If no images.featured=1
, then I want to select min of sort
.
Currently, the specified area selects a min sort
image for each vessel_id
source share