---
title: "Querying — Sluggable for Laravel | Roundly"
description: "Find models by slug — exact locale or the fallback chain, any locale, lists — with scopes that stay safe for count() and paginate()."
url: https://roundly-consulting.com/open-source/docs/sluggable-for-laravel/querying
language: en
---

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

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

# Querying

```php
Product::whereSlug('red-chair')->first();                   // default column
Product::whereSlug('rc-01', column: 'handle')->first();
Topic::whereSlug('investovanie', locale: 'sk')->first();     // exact locale
Topic::whereSlug('investing')->first();                     // chain: current → fallback → supported
Topic::whereSlugIn(['a', 'b'])->get();
Topic::whereSlugInAnyLocale('investing')->first();          // current, fallback, supported, listed
Topic::whereSlug('gift')->orderBySlugPreference('gift')->first();
Product::findBySlug('red-chair');                            // ?Product (adds the preference order)
Product::findBySlugOrFail('red-chair');                      // ModelNotFoundException → 404
```

- whereSlug($slug, column:, locale:) — an explicit locale is exact; null follows the definition’s chain: current, then fallback, then (for Any) every supported locale and any listed in locales().
- whereSlugIn() takes an array (a list or not — array\_filter() output works), whereSlugInAnyLocale() ignores the chain and searches every resolvable locale (current, fallback, supported, listed), orderBySlugPreference() ranks the current locale first, then the fallback.
- findBySlug() returns the model or null and adds the preference order; findBySlugOrFail() throws ModelNotFoundException — a 404 in a controller.
- Passing a locale for a string column throws InvalidSlugDefinitionException (localeOptionOnStringColumn).

Scopes add predicates only — never an ORDER BY — so ->count(), ->paginate() and whereHas() sub-queries work on every engine; only the finders and route binding add the locale-preference order. Reads apply the model’s normal global scopes.

Packages with a swappable model should call the scopes through their seam (PostModel::query()->whereSlug(…)) rather than Post::findBySlug(…) — late static binding ignores the swap.

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