I convert your sql code adding DB Raw for the first leftjoin.
$collection = DB::table('contactinfo as ci')
->select('ci.id','ci.id_category','ci.subject','cit.name AS catname')
->leftJoin('contactinfo_notes cin', 'cin.id','=',DB::Raw('SELECT id FROM contactinfo_notes cin2 WHERE cin2.id_ci=ci.id AND cin2.deleted=0 ORDER BY cin2.id DESC LIMIT 1')
->leftJoin('contactinfo_types cit', 'cit.id','=','ci.id_category')->get();
Or you can remplace the first leftjoin with this code , witch is more readble.
->leftJoin('contactinfo_notes cin2', function($join)
{
$join->on('cin2.id_ci', '=', 'ci.id')
->where('cin2.deleted', 0)
->orderBy('cin2.id', 'DESC')
->take(1)->get();
})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…