This is what i have been able to produce so far:
DB::table('users as u')
->select(['u.name','u.photo','m.*'])
->join('message as m','u.id','=','m.useridsend')
->join(DB::raw('( SELECT useridsend, MAX(created_at) AS created_at FROM messages GROUP BY useridsend ) AS r'),function($join)
{
$join->on('m.useridsend','=','r.useridsend')
->On('m.creaded_at','=','r.created_at');
})->where('m.useridreceive','=',2)->orderBy('m.created_at','DESC')->toSql();
//Tinker Output:
'select `u`.`name`, `u`.`photo`, `m`.* from `users` as `u` inner join `message` as `m` on `u`.`id` = `m`.`useridsend` inner join ( SELECT useridsend, MAX(created_at) AS created_at FROM messages GROUP BY useridsend ) AS r on `m`.`useridsend` = `r`.`useridsend` and `m`.`creaded_at` = `r`.`created_at` where `m`.`useridreceive` = ? order by `m`.`created_at` desc'
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community