Illuminate\Database\Eloquent\Builder::whereHas PHP Method

whereHas() public method

Add a relationship count / exists condition to the query with where clauses.
public whereHas ( string $relation, Closure $callback = null, string $operator = '>=', integer $count = 1 ) : Builder | static
$relation string
$callback Closure
$operator string
$count integer
return Builder | static
    public function whereHas($relation, Closure $callback = null, $operator = '>=', $count = 1)
    {
        return $this->has($relation, $operator, $count, 'and', $callback);
    }

Usage Example

 public static function scopeWithTag(Builder $query, $tags, $type = 'slug')
 {
     $tags = (new static())->prepareTags($tags);
     return $query->whereHas('tags', function ($query) use($type, $tags) {
         $query->whereIn($type, $tags);
     });
 }
All Usage Examples Of Illuminate\Database\Eloquent\Builder::whereHas