DB::table('tasks')
->leftJoin('comments','comments.task_id', '=', 'tasks.id')
->select('tasks.*','comments.id as comments_id' )
->groupBy('tasks.id')
->get();
public function comments()
{
return $this->hasMany('App\Comments');
}
Task::find($id)->comments()->count();
$count = 0;
foreach(Task::All() as $task)
{
$count += $task->comments()->count();
}