---
title: "Filters — Plausible for Laravel | Roundly"
description: "Type-safe where()/orWhere() filters for Stats v2, custom-property filters, and the raw v1 string and v2 array forms."
url: https://roundly-consulting.com/open-source/docs/plausible-for-laravel/filters
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Plausible for Laravel](https://roundly-consulting.com/open-source/docs/plausible-for-laravel.md)

# Filters

Build Stats v2 filters fluently with where() and orWhere(). Each takes a field (a Dimension, Property or string), an operator (a FilterOperator or string) and a value — a scalar or a list:

```php
use RoundlyConsulting\Plausible\Enums\Dimension;
use RoundlyConsulting\Plausible\Enums\FilterOperator;
use RoundlyConsulting\Plausible\Enums\Metric;

$result = Plausible::stats()
    ->for('my-site.com')
    ->metrics(Metric::Visitors)
    ->where(Dimension::VisitBrowser, FilterOperator::Is, 'Chrome')
    ->where('visit:os', 'is', ['Mac', 'Windows'])                 // implicit AND, list value
    ->orWhere(Dimension::VisitCountry, FilterOperator::Is, 'US')  // OR with the previous
    ->run();
```

Multiple where() calls combine with an implicit AND. orWhere() folds the previous filter and the new one into an or group, and further orWhere() calls extend that same group; a leading orWhere() behaves like where(). Both compile to Plausible’s array form:

```php
// ->where(Dimension::VisitBrowser, FilterOperator::Is, 'Chrome')
['is', 'visit:browser', ['Chrome']];

// ->where('visit:browser', 'is', 'Chrome')
// ->orWhere('visit:browser', 'is', 'Firefox')
// ->orWhere('visit:browser', 'is', 'Safari')
['or', [
    ['is', 'visit:browser', ['Chrome']],
    ['is', 'visit:browser', ['Firefox']],
    ['is', 'visit:browser', ['Safari']],
]];
```

## Custom event properties

```php
// Filter on a custom event property — Dimension::custom('plan') returns 'event:props:plan'
Plausible::stats()
    ->for('my-site.com')
    ->metrics(Metric::Visitors, Metric::Events)
    ->where(Dimension::custom('plan'), FilterOperator::Is, 'pro')
    ->run();
```

## Raw filters

filter() accepts both raw shapes. A string uses the legacy v1 syntax and applies to aggregate(), timeseries() and breakdown(); several are joined with a semicolon. An array uses the v2 form and applies to run():

```php
// v1 terminals take the legacy string syntax; several filters are joined with ';'
Plausible::stats()
    ->for('my-site.com')
    ->filter('visit:browser==Chrome')
    ->filter('visit:country==FR')
    ->aggregate();

// run() takes the v2 array form — the same shape where() compiles to
Plausible::stats()
    ->for('my-site.com')
    ->filter(['is', 'visit:browser', ['Chrome']])
    ->run();
```

where(), orWhere() and array filters target the run() terminal only — the v1 terminals ignore them, so use string filters there.

## Operators

| Case | Wire value |
| --- | --- |
| `FilterOperator::Is` | is |
| `FilterOperator::IsNot` | is\_not |
| `FilterOperator::Contains` | contains |
| `FilterOperator::ContainsNot` | contains\_not |
| `FilterOperator::Matches` | matches |
| `FilterOperator::MatchesNot` | matches\_not |
| `FilterOperator::And_` | and |
| `FilterOperator::Or_` | or |
| `FilterOperator::Not` | not |
| `FilterOperator::HasDone` | has\_done |
| `FilterOperator::HasNotDone` | has\_not\_done |

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/plausible-for-laravel.md)
