我只需要选择具有唯一值“ who_id”的条目。但是在这种情况下,我得到了所有记录。
$history_today = DB::table('view_history')
->select('girl_id', 'who_id', 'girls.name as name', 'girls.main_image',
'view_history.time', 'girls.age', 'cities.name as city_name',
'girls.city_id')
->where('girl_id', $girl->id)
->where('who_id', '!=', null)
->where('who_id', '!=', $girl->id)
->leftJoin('girls', 'girls.id', '=', 'view_history.who_id')
->leftJoin('cities', 'girls.city_id', '=', 'cities.id_city')
->orderBy('time', 'DESC')
->distinct('who_id')
->paginate(15);