---
title: "Querying and search — Translatable for Laravel | Roundly"
description: "Driver-agnostic per-locale scopes, a missing-locale scope for fill queues, and literal, case-insensitive search across locales."
url: https://roundly-consulting.com/open-source/docs/translatable-for-laravel/querying
language: en
---

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

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

# Querying and search

## Query scopes

HasTranslations adds three JSON-path scopes that work on every supported engine. The locale defaults to the app locale:

```php
Topic::query()->whereLocale('name', 'Investing', 'en')->get(); // exact per-locale value (locale defaults to app locale)
Topic::query()->whereHasLocale('name', 'sk')->get();           // rows with a non-blank 'sk' value
Topic::query()->whereMissingLocale('name', 'sk')->get();       // rows missing 'sk' (feed an AI-fill queue)
```

Each scope checks that the field is translatable (NotATranslatableAttributeException otherwise) and validates the locale format (InvalidLocaleException), so a request-supplied locale never reaches the JSON-path expression unchecked. Pass the bare attribute name: the scopes and Translatable::search() qualify it with the model’s table (topics.name->en), so they work on a query that joins another table with a name column. whereMissingLocale() pairs naturally with a fill queue:

```php
Topic::query()
    ->whereMissingLocale('description', 'sk')
    ->each(fn (Topic $topic) => FillMissingTranslations::dispatch($topic, 'description'));
```

## Search across locales

Translatable::search() adds a per-locale, case-insensitive search across one or more fields and every supported locale — ilike on PostgreSQL, a lowercased like on MySQL and SQLite:

```php
use RoundlyConsulting\Translatable\DataTransferObjects\TranslationSearch;
use RoundlyConsulting\Translatable\Facades\Translatable;

$topics = Translatable::search(
    Topic::query(),
    new TranslationSearch(fields: ['name', 'description'], term: 'invest'),
)->get();

// The term is a literal substring — this matches "100%", not every row:
Translatable::search(Topic::query(), new TranslationSearch(fields: ['name'], term: '100%'))->get();
```

The term is treated as a literal substring: %, \_ and \\ are escaped and the SQL states its escape character explicitly, so a search for 100% or a\_b finds exactly those rows on every engine — including SQLite, which has no default LIKE escape character. The term is always bound; only the searched field name, validated as a plain identifier, reaches the SQL. A search with no fields (or no supported locale) searches nothing and matches no rows — never every row.

PostgreSQL’s ilike and MySQL’s lower() fold diacritics too, so čaj finds Čaj. SQLite’s built-in lower() folds ASCII letters only, so there it doesn’t — a SQLite test of diacritic search sees misses that PostgreSQL and MySQL don’t have.

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