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

[5.x] Add firstOrfail, firstOr, sole and exists methods to base query builder #9976

Open
wants to merge 5 commits into
base: 5.x
Choose a base branch
from

Conversation

duncanmcclean
Copy link
Member

This pull request adds various useful methods to Statamic's base query builder:

  • firstOrFail
    • Gets the first result if one exists, otherwise, it throws an exception.
  • firstOr
    • Gets the first result if one exists, otherwise, it executes the provided callback.
  • sole
    • Gets the first & only item if one exists. It'll throw an exception if no results can be found or if more than 1 result is found.
  • exists
    • Returns true if the query returns one or more results.

On the back of #9815, I was thinking a few of Laravel's first/find methods could be added to our "base" query builder since they're useful for everything, not just entries & terms.

…-base-query-builder

# Conflicts:
#	tests/Data/Entries/EntryQueryBuilderTest.php
@duncanmcclean duncanmcclean changed the base branch from 4.x to 5.x May 13, 2024 11:48
@duncanmcclean duncanmcclean changed the title [4.x] Add firstOrfail, firstOr, sole and exists methods to base query builder [5.x] Add firstOrfail, firstOr, sole and exists methods to base query builder May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant