通过一个字段选择唯一记录

时间:2019-06-29 18:53:56

标签: php laravel-5 query-builder laravel-5.8

我只需要选择具有唯一值“ 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);

0 个答案:

没有答案