实现一下dcat/laravel-wherehasin的每个方法
时间: 2024-03-11 07:48:21 浏览: 19
dcat/laravel-wherehasin提供了以下几个方法:
1. `whereIn($relation, $values, $boolean = 'and', $not = false)`: 添加一个关系查询的IN条件。
```php
public function whereIn($relation, $values, $boolean = 'and', $not = false)
{
$this->query->whereHas($relation, function ($query) use ($values, $not) {
$query->whereIn($this->getRelationKey(), $values, 'and', $not);
}, $boolean);
return $this->query;
}
```
2. `whereNotIn($relation, $values, $boolean = 'and')`: 添加一个关系查询的NOT IN条件。
```php
public function whereNotIn($relation, $values, $boolean = 'and')
{
return $this->whereIn($relation, $values, $boolean, true);
}
```
3. `orWhereIn($relation, $values)`: 添加一个关系查询的OR IN条件。
```php
public function orWhereIn($relation, $values)
{
return $this->whereIn($relation, $values, 'or');
}
```
4. `orWhereNotIn($relation, $values)`: 添加一个关系查询的OR NOT IN条件。
```php
public function orWhereNotIn($relation, $values)
{
return $this->whereIn($relation, $values, 'or', true);
}
```