Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pending PR] Document findOrNew, firstOrCreate & similar methods on Entry & Term query builders #1325

Draft
wants to merge 44 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
65b6632
add upgrade guide
jasonvarga Feb 27, 2024
7826620
explain that seeds are removed from shuffle modifier
jasonvarga Mar 6, 2024
dd556ec
[5.x] Document Addon Testing (#1258)
duncanmcclean Mar 13, 2024
65a31ff
[5.x] Remove docs for the Antlers Regex Parser (#1242)
duncanmcclean Mar 13, 2024
7704119
Merge remote-tracking branch 'origin/master' into 5.0
duncanmcclean Mar 13, 2024
a7226f6
fill in min php/laravel versions, and recommend upgrading
jasonvarga Mar 14, 2024
9fba930
please
jasonvarga Mar 14, 2024
88f1a36
nevermind i figured it out
jasonvarga Mar 14, 2024
62cf613
slugs
jasonvarga Mar 20, 2024
6d30bd1
explain how to use temporary file uploads
jasonvarga Mar 28, 2024
fcc2a83
Tweak note about supported Laravel versions
duncanmcclean Mar 28, 2024
0fe2703
[5.x] Update string based validation rules (#1298)
jesseleite Mar 28, 2024
07ad278
link to upgrade guides so we dont have maintain two identical lists
jasonvarga Mar 28, 2024
101a122
document rule changes
jasonvarga Mar 28, 2024
1a298d1
explain fake sql queries and how to disable them
jasonvarga Apr 1, 2024
c052016
[5.x] Document new `findOrFail` methods on repositories (#1305)
duncanmcclean Apr 2, 2024
9dd1d10
Merge remote-tracking branch 'origin/master' into 5.0
duncanmcclean Apr 2, 2024
ac6eb69
Terms repository: Add note about `findOrFail` now we have a `find` ex…
duncanmcclean Apr 2, 2024
557f3ac
bard
jasonvarga Apr 2, 2024
2a5fab7
helpers are removed
jasonvarga Apr 3, 2024
4517940
Merge remote-tracking branch 'origin/master' into 5.0
duncanmcclean Apr 4, 2024
3a5d4d5
SVG tag: The default value for the `sanitize` parameter is now `true`
duncanmcclean Apr 4, 2024
045de7e
[5.x] Multi-site documentation overhaul (#1307)
jesseleite Apr 5, 2024
58fe06e
sites
jasonvarga Apr 5, 2024
67ee3f4
Tweak sites.
jesseleite Apr 5, 2024
1b3c956
Note on text `direction`.
jesseleite Apr 5, 2024
4615188
[5.x] Upgrade Guide: Add note about pagination view changes (#1312)
duncanmcclean Apr 8, 2024
b95a760
more upgrade guiding
jasonvarga Apr 9, 2024
e730520
not anymore
jasonvarga Apr 10, 2024
a971299
escaping params
jasonvarga Apr 10, 2024
651cbd4
Move `content/sites.yaml` to `resources/settings/sites.yaml`.
jesseleite Apr 10, 2024
d82003e
Move `resources/settings/sites.yaml` to `resources/sites.yaml`.
jesseleite Apr 10, 2024
f75e2d0
Update screenshot, since we moved `Sites` into `Settings` section.
jesseleite Apr 11, 2024
d6e2fb5
Update `AddonTestCase` import in upgrade guide
duncanmcclean Apr 12, 2024
0f96ca2
Add "Testing in Addons" page to Extending docs (#1323)
duncanmcclean Apr 15, 2024
cd068ed
Add note to upgrade guide about the new `please` file
duncanmcclean Apr 15, 2024
8514375
Add note to the upgrade guide about the Laravel Shift discount
duncanmcclean Apr 15, 2024
baa8da9
Merge branch '5.0' of github.com:statamic/docs into 5.0
duncanmcclean Apr 15, 2024
f99671f
Document new methods on "Entry Repository" page
duncanmcclean Apr 15, 2024
a7e6cbf
Document new methods on "Term Repository" page
duncanmcclean Apr 15, 2024
38329f2
Merge remote-tracking branch 'origin/5.0' into cms-9815
duncanmcclean Apr 15, 2024
8717943
Merge remote-tracking branch 'origin/master' into 5.0
duncanmcclean Apr 18, 2024
4a5e66c
Merge remote-tracking branch 'origin/5.0' into cms-9815
duncanmcclean Apr 18, 2024
53f9305
Merge branch 'master' into cms-9815
duncanmcclean May 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion content/collections/repositories/entry-repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ 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 the entry cannot be found. |
| `findOrFail($id)` | Get Entry by `id`. Throws an `EntryNotFoundException` when entry can not be found. |
| `findOrNew($id)` | Finds Entry by `id` or returns fresh `Entry` instance. |
| `findOr($id, $callback)` | Finds Entry by `id` or call a callback. |
| `firstOrNew($attributes, $values)` | Finds entry with the provided `$attributes`. If one can't be found, a new `Entry` instance will be returned with `$values`. |
| `firstOrCreate($attributes, $values)` | Finds entry with the provided `$attributes`. If one can't be found, a new `Entry` instance will be returned and saved with `$values`. |
| `updateOrCreate($attributes, $values)` | Finds entry with the provided `$attributes` and updates it using provided `$values`. If one can't be found, a new `Entry` instance will be returned and saved. |
| `query()` | Query Builder |
| `whereCollection($handle)` | Get all Entries in a `Collection` |
| `whereInCollection([$handles])` | Get all Entries in an array of `Collections` |
Expand Down Expand Up @@ -182,6 +187,31 @@ Entry::query()
```
:::

### Find entry or call a callback

```php
Entry::query()
->where('collection', 'news')
->findOr('my-entry', function () {
return Entry::make()->collection('news')->set('title', 'Breaking news');
);
```

This can also be simplified to `Entry::findOr('my-entry', ...)`.

### Find entry or create an entry

```php
Entry::query()
->where('collection', 'news')
->firstOrCreate(
['slug' => 'breaking-news'],
['title' => 'Breaking News']
);
```

This can also be simplified to `Entry::firstOrCreate($attributes, $values)`

## Creating

Start by making an instance of an entry with the `make` method.
Expand Down
30 changes: 30 additions & 0 deletions content/collections/repositories/term-repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ use Statamic\Facades\Term;
| `find($id)` | Get Term by `id` |
| `findByUri($uri)` | Get Term by `uri` |
| `findOrFail($id)` | Get Term by `id`. Throws a `TermNotFoundException` when the term cannot be found. |
| `findOrNew($id)` | Finds Term by `id` or returns fresh `Term` instance. |
| `findOr($id, $callback)` | Finds Term by `id` or call a callback. |
| `firstOrNew($attributes, $values)` | Finds term with the provided `$attributes`. If one can't be found, a new `Term` instance will be returned with `$values`. |
| `firstOrCreate($attributes, $values)` | Finds term with the provided `$attributes`. If one can't be found, a new `Term` instance will be returned and saved with `$values`. |
| `updateOrCreate($attributes, $values)` | Finds term with the provided `$attributes` and updates it using provided `$values`. If one can't be found, a new `Term` instance will be returned and saved. |
| `query()` | Query Builder |
| `make()` | Makes a new `Term` instance |

Expand Down Expand Up @@ -83,6 +88,31 @@ Term::query()
->get();
```

### Find term or call a callback

```php
Term::query()
->where('taxonomy', 'tags')
->findOr('my-term', function () {
return Term::make()->taxonomy('tags')->set('title', 'Blog');
);
```

This can also be simplified to `Term::findOr('my-term', ...)`.

### Find entry or create an entry

```php
Term::query()
->where('taxonomy', 'tags')
->firstOrCreate(
['slug' => 'blog'],
['title' => 'Blog']
);
```

This can also be simplified to `Term::firstOrCreate($attributes, $values)`


## Creating

Expand Down