Skip to content

Commit

Permalink
Combine Two "whereHas"
Browse files Browse the repository at this point in the history
  • Loading branch information
curder committed Nov 15, 2023
1 parent 1f40189 commit 911988e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/partials/model-relations.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,16 @@ auth()->user()->posts()->create([
// Project -> belongsTo(User::class)

$project->user->update(['email' => '[email protected]']);
```

## 组合两个 `whereHas`

在模型关系中,可以将 `whereHas()``orDoesntHave()` 组合在一个查询中。

```php
User::whereHas('roles', function($query) {
$query->where('id', 1);
})
->orDoesntHave('roles')
->get();
```

0 comments on commit 911988e

Please sign in to comment.