Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel eager loading pass variable in withCount where condition

$user = 1;
                       
Forum::with(['posts' => function($query) use ($user){
    $query->withCount(['comments => function($query) use ($user){
            $query->where('id_user', $user); 
        }]);
}])
->get();
 
PREVIOUS NEXT
Tagged: #laravel #eager #loading #pass #variable #withCount #condition
ADD COMMENT
Topic
Name
8+7 =