Radical Design Course by Jack McDade

From the creator of Statamic

Learn how to make your websites standout and be remembered.

For a software dev like me who has no idea how to create a cute hand-drawn dashed line, this course just 100% works.

— Ira Zayats, Developer

Entry Repository

To work with the Entry Repository, use the following Facade:

use Statamic\Facades\Entry;


Methods Description
all() Get all Entries
find($id) Get Entry by id
findByUri($uri, $site) Get Entry by uri, optionally in a site
findOrFail($id) Get Entry by id. Throws an EntryNotFoundException when the entry cannot be found.
query() Query Builder
whereCollection($handle) Get all Entries in a Collection
whereInCollection([$handles]) Get all Entries in an array of Collections
make() Makes a new entry instance



Get a single entry by its id

Entry::query()->where('id', 123)->first();
// Or with the shorthand method

When an entry can't be found, the Entry::find() method will return null. If you'd prefer an exception be thrown, you may use the findOrFail method:


Get an entry by its URI

Entry::query()->where('uri', 'blog/my-first-post')->first();
// Or with the shorthand method
Hot Tip!

What is the difference between URI and URL? URL includes the site root (e.g. /fr/ in a multisite), if there is one, while URI is site agnostic and will not. As you may have surmised, when you only have a single site — they are identical.

Get all entries in a collection

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

Get an entry from a collection by its slug

->where('collection', 'blog')
->where('slug', 'my-first-post')

Get an entry by its slug in a multi-site install

->where('collection', 'team')
->where('slug', 'director')
->where('site', 'albuquerque')

Get all Pre-Y2K news

->where('collection', 'news')
->where('date', '<', '2000')

Get all of today's news

use Illuminate\Support\Carbon;
->where('collection', 'news')
->where('date', Carbon::parse('today'))

Get the last 12 months of news

use Illuminate\Support\Carbon;
->where('collection', 'news')
->where('date', '>=', Carbon::parse('now')->subYears(1))

Find all entries authored by Jack

$author = User::findByEmail('[email protected]');
->where('collection', 'news')
->where('author', $author->id())

Get all entries using a specific Blueprint

->where('blueprint', 'editorial')

Get all published and scheduled entries

->whereIn('status', ['published', 'scheduled'])
Hot Tip!

What is the difference between querying against published and status? Read more on date behavior and published status!

Get all entries with taxonomy terms

When you want to query all entries with a specific term, you should use the whereTaxonomy method:

->where('collection', 'news')

In the above example, categories is the taxonomy's handle and laravel is the term's slug.

When you want to query all entries with multiple terms, you should instead use the whereTaxonomyIn method:

->where('collection', 'news')
->whereTaxonomyIn(['categories::laravel', 'categories::statamic'])

This only works when the taxonomy is linked in your collection's config. If it's not linked in the collection config, you should use the whereJsonContains method instead:

->where('collection', 'news')
->whereJsonContains('categories_field', ['laravel', 'statamic'])


Start by making an instance of an entry with the make method.
You need at least a slug and the collection before you can save an entry.

$entry = Entry::make()->collection('blog')->slug('my-entry');

You may call additional methods on the entry to customize it further.

->date($carbon) // or string of Y-m-d or Y-m-d-Hi
->published(true) // or false for a draft
->locale('default') // the site handle. defaults to the default site.
->blueprint('article') // set entry blueprint
->data(['foo' => 'bar']) // an array of data (front-matter)
->origin($origin); // another entry instance

Finally, save it. It'll return a boolean for whether it succeeded.

$entry->save(); // true or false

Setting an entry's parent

When you're creating entries in structured collections, you may find yourself needing to programatically set an entry's parent.

Parent & children pages are stored in structures, which live in "trees", rather than in the entry data. This means that in order to set an entry's parent, we will need to append it to the structure.

// Create your entry as normal...
$entry = Entry::make()
// ...
// Before saving the entry, define an "afterSave" callback to append the
// new entry to the tree, under the parent.
$entry->afterSave(function ($entry) {
$parent = Entry::find('the_parent_entry');
->appendTo($parent->id(), $entry->id())
// And finally, save the entry.
HR: Section
Learn More!

There is more to learn more in these related articles:




HR: Section
Docs feedback

Submit improvements, related content, or suggestions through Github.

Betterify this page →