Statamic has a number of query builders that provide a convenient, fluent interface for retrieving data. It's very similar to Eloquent in Laravel.

Retrieving results

You may use the query method on a number of repository classes to begin a query. This method returns a fluent query builder instance for the given item, allowing you to chain more constraints onto the query then get the results using the get method.

For example, here’s how you could get all the entries:


This would typically return a Collection of the items. In this case, it’d be full of Entry objects.

Filtering results

In the example above, you may notice it’s exactly the same as running Entry::all(). The power of using the query builder is to let you chain more complex restraints onto it. For instance, you could filter down the items.

You may use the where method to add simple where clauses:

    ->where('collection', 'blog')
    ->where('food', 'bacon')

You may use the whereIn method to check against an array of values:

    ->whereIn('food', ['bacon', 'cheese'])

Filtering by taxonomies

If you want to filter by a taxonomy term, you can use whereTaxonomy. For instance:


Ordering, Limit, and Offset

The orderBy method allows you to sort by a given field:

Entry::query()->orderBy('title', 'desc')->get();

You may limit and/or skip results by using the limit and offset methods:



The count method allows you to get the number of records.



You may paginate a result set by finishing your query with the paginate method.


This will return an instance of Illuminate\Pagination\LengthAwarePaginator.

Available Query Builders


Query against all assets.

    ->where('container', 'main')
    ->where('folder', 'images')
    ->where('alt', 'like', '%potato%')

The container and folder columns will allow you to refine the location of the assets, where any other column will filter from asset data values.

Asset Container Assets

Query against all assets in a particular container. Similar to the above query, but with the container already implied.

    ->where('folder', 'images')


Query against all entries.

    ->where('title', 'like', '%hello%')

Collection Entries

Query against entries in a particular collection. Similar to the above query, but with the container already implied.

    ->where('title', 'like', '%news%')

Global Fields

Get access to Global fields from your PHP files.

use Statamic\Facades\GlobalSet;



Query against all users.

    ->where('email', '[email protected]')

User Group Users

Query against users in a particular user group. Similar to the above query, but with the group already implied.

    ->where('mustache', true)


The Statamic query builder are similar to Laravel’s Eloquent and database query builders, but they are not entirely the same.

Where the Laravel query builders would translate to SQL under the hood, the Statamic equivalent ones may not. So, for instance, you cannot use features such a raw SQL expressions, joins, etc.

If you have re-bound a particular repository or query builder to an Eloquent equivalent, you may be able to use these features, however if you intend to distribute it in an addon, keep in mind that not everyone may be using a database.

Betterify this page on Github!