Skip to content

Commit

Permalink
Add where
Browse files Browse the repository at this point in the history
  • Loading branch information
curder committed Nov 15, 2023
1 parent 4cafc66 commit 5cefcb3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/partials/model-relations.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ public function productsByName()
}
```

## 条件关系

如果发现经常使用相同的关系和附加 `where` 条件,则可以创建单独的关系方法。

```php
public function comments()
{
return $this->hasMany(Comment::class);
}

public function approvedComments()
{
return $this->hasMany(Comment::class)->where('approved', 1);
}
```

## 将条件语句添加到多对多关系

在多对多关系中,可以使用 `wherePivot` 方法将 where 语句添加到数据中间表。
Expand Down

0 comments on commit 5cefcb3

Please sign in to comment.