---
title: "Query scopes — Addresses for Laravel | Roundly"
description: "Filter addresses with the primary(), ofType() and inCountry() scopes — on the model, on any owner’s relation, or combined."
url: https://roundly-consulting.com/open-source/docs/addresses-for-laravel/query-scopes
language: en
---

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

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

# Query scopes

```php
use RoundlyConsulting\Addresses\Address;
use RoundlyConsulting\Addresses\Enums\AddressType;

Address::query()->primary()->get();
Address::query()->ofType(AddressType::Billing)->get();
Address::query()->inCountry('SK')->get();

// combine them, on the model or on any owner's relation
Address::query()->primary()->ofType(AddressType::Shipping)->inCountry('sk')->count();
$company->addresses()->inCountry('US')->ofType(AddressType::Office)->get();

// soft-deleted rows are excluded unless you ask for them
Address::withTrashed()->inCountry('SK')->get();
```

| Scope | Filters to |
| --- | --- |
| `primary()` | is\_primary = true |
| `ofType(AddressType $type)` | type = the enum’s value |
| `inCountry(string $iso)` | country\_iso = the trimmed, upper-cased code; compared case-insensitively with normalise\_country off |

inCountry() matches codes the way they were stored: with normalise\_country on it trims and upper-cases its argument (' sk ' finds SK); with it off it compares case-insensitively ('SK' finds a verbatim sk). Alpha-2 and alpha-3 codes are never mapped onto each other — SK never matches SVK — so store one style consistently.

The model uses soft deletes, so every query excludes deleted addresses unless you add withTrashed() or onlyTrashed(). With a custom model, call the scopes on your own class — they are inherited.

## 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/addresses-for-laravel.md)
