cms
cms copied to clipboard
[5.x] Add `findOrNew`, `firstOrCreate`, `createOrUpdate` (& related methods) methods to Entry & Term query builders
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.
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.
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 🙏🏻