This is my code to fetch projects which are related to a user:
$query = Project::query()
->leftJoin('ProjectUser', 'ProjectUser.project_id = Project.id')
->where('ProjectUser.user_id = :userId:', array('userId' => $user->id))
->orderBy('Project.last_activity_at DESC');
When I do $query->execute()
I get all related records and could count them. But in this I case I want to count all records instead of fetch and count it. So, is there a way to count it directly?
Thank you for any responses.