Okay after hours of research and still using DB::select I have to ask this question. Because I am about to trough my computer away ;).
I want to get the last input o
You can use following addon to handle all subquery related function from laravel 5.5+
https://github.com/maksimru/eloquent-subquery-magic
User::selectRaw('user_id,comments_by_user.total_count')->leftJoinSubquery(
//subquery
Comment::selectRaw('user_id,count(*) total_count')
->groupBy('user_id'),
//alias
'comments_by_user',
//closure for "on" statement
function ($join) {
$join->on('users.id', '=', 'comments_by_user.user_id');
}
)->get();