Skip to content

Commit

Permalink
Document Entry::findOrFail() method
Browse files Browse the repository at this point in the history
Closes #1249.

Related: statamic/cms#9506
  • Loading branch information
duncanmcclean committed Feb 27, 2024
1 parent f25c0c4 commit fc4a628
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions content/collections/repositories/entry-repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use Statamic\Facades\Entry;
| `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 entry can not be found. |
| `query()` | Query Builder |
| `whereCollection($handle)` | Get all Entries in a `Collection` |
| `whereInCollection([$handles])` | Get all Entries in an array of `Collections` |
Expand All @@ -40,6 +41,12 @@ Entry::query()->where('id', 123)->first();
Entry::find(123);
```

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

```php
Entry::findOrFail(123);
```

#### Get an entry by its URI

```php
Expand Down

0 comments on commit fc4a628

Please sign in to comment.