DEV Community

Discussion on: Laravel 8.x withExists Method to Eloquent Queries Example

Collapse
 
lk77 profile image
Mathias E.

This syntax will not work for some reasons :

User::withExists([
        'posts as is_author',
        'posts as is_tech_author' => function ($query) {
            return $query->where('category', 'tech');
        },
        'comments',
    ])->select([... some fields to select ...])->get();
Enter fullscreen mode Exit fullscreen mode

the ->select() call needs to be before ->withExists call