Skip to content

Commit 75da448

Browse files
committed
update Model::has() and Model::hasNo() with nesting and scoping
1 parent dedd1b7 commit 75da448

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

v5/relationships.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,18 @@ When retrieving model records, you can limit your results based on the existence
337337
```php
338338
ExampleModel::new()->has('tags')->get();
339339
ExampleModel::new()->hasNo('tags')->get();
340+
```
341+
342+
You can also scope and nest existence queries:
343+
344+
```php
345+
use \App\Models\Blog;
346+
use \App\Models\Post;
347+
348+
ExampleModel::new()->has('publishedBlog', function(Blog $query) {
349+
$query->has('posts', function(Post $query) {
350+
$table = $query->getTable();
351+
$query->where("{$table}.post_status", 'draft');
352+
});
353+
})->get();
340354
```

0 commit comments

Comments
 (0)