$user = 1;
Forum::with(['posts' => function($query){
$query->withCount(['comments => function($query){
$query->where('id_user', $user);
}]);
}])
->get();
How to pass the value of the $user variable to $query->where('id_user', $user);
$user is not working (appears underlined in red in the editor).
CodePudding user response:
$user = 1;
Forum::with(['posts' => function($query) use ($user){
$query->withCount(['comments => function($query) use ($user){
$query->where('id_user', $user);
}]);
}])
->get();