-
-
Notifications
You must be signed in to change notification settings - Fork 548
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
[5.x] Add findOrNew
, firstOrCreate
, createOrUpdate
(& related methods) methods to Entry & Term query builders
#9815
base: 5.x
Are you sure you want to change the base?
Conversation
I removed the createOrFirst method as Statamic does not throw an exception when the entry/term already exists. This means the method would always create/update and never just return the entry/term. |
@duncanmcclean unless you had any other comments on major portions of this, I think it is ready for review? |
Thanks! We'll review this when we can. |
findOrNew
, firstOrCreate
, createOrUpdate
(& related methods) methods to Entry & Term query builders
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work on this pull request!
I've made a couple of tweaks to the tests and implemented a few of the other methods missing from our query builder implementation.
I've also opened #9976 which includes some of the methods useful for all of Statamic's query builders.
Wow thank you for all of these improvements! This will help a ton in our use cases. |
Thanks @godismyjudge95 for dedicating your time to this, such a great PR. I'd love to see this merged 🙏🏻 |
This PR adds a few helper methods to the repositories/facades: firstOrCreate and updateOrCreate.
These methods exist on Laravel eloquent models:
https://laravel.com/docs/11.x/eloquent#retrieving-or-creating-models
https://laravel.com/docs/11.x/eloquent#updates
As a result, this PR attempts to replicate that functionality but for Statamic's content types.
I am marking this as a draft as I would like to implement this for all reasonable facades/repositories.
If I am off track on the implementation feel free to point it out.