跳过laravel中数据库中的重复数据

跳过laravel中数据库中的重复数据,laravel,distinct,Laravel,Distinct,我只想跳过数据库中的重复数据,我的外键正在重复,所以我只想跳过重复条目,只获取最新的数据 我的控制器就是这样 $old=DB::table('tabl-1') ->leftJoin('tbl-2','tabl1.id','=','tabl2.tabl1_id') ->whereDate('created_at','<' ,Carbon::today()) ->select('tbl1.name as name','tbl1.class as cla

我只想跳过数据库中的重复数据,我的外键正在重复,所以我只想跳过重复条目,只获取最新的数据 我的控制器就是这样

$old=DB::table('tabl-1')
    ->leftJoin('tbl-2','tabl1.id','=','tabl2.tabl1_id')
    ->whereDate('created_at','<' ,Carbon::today())
    ->select('tbl1.name as name','tbl1.class as class','tabl2.table1_id')
    ->distinct('tabl2.table1_id')
    ->get()
    ->toArray();
$old=DB::table('tabl-1')
->leftJoin('tbl-2','tabl1.id','=','tabl2.tabl1_id'))
->whereDate('created_at','DB::table('first')->leftJoin('second','first.id','=','second.first_id'))
->whereDate('first.created_at','
DB::table('first')->leftJoin('second', 'first.id', '=', 'second.first_id')
->whereDate('first.created_at', '<', Carbon::today())
->select('first.name as name', 'first.class as class', 'second.first_id')
->groupBy('second.first_id')->get()->toArray();