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

[7.x] Added firstWhereOrFail to Eloquent Builder #31134

Closed
wants to merge 5 commits into from
Closed

[7.x] Added firstWhereOrFail to Eloquent Builder #31134

wants to merge 5 commits into from

Conversation

eusonlito
Copy link
Contributor

@eusonlito eusonlito commented Jan 15, 2020

Extend Eloquent Builder with method firstWhereOrFail to complement firstWhere.

A shortcut for ->where(...)->firstOrFail().

Example: I'm fetching a user by email address:

// Before
User::where('email', 'foo@bar.com')->firstOrFail();

// After
User::firstWhereOrFail('email', 'foo@bar.com');

Implementation Notes:

I only added this to the Eloquent builder for now. As commented on #31089 I have avoided to add this method on the Query builder due failed tests.

Thanks!

@driesvints driesvints changed the title Added firstWhereOrFail to Eloquent Builder [7.x] Added firstWhereOrFail to Eloquent Builder Jan 15, 2020
@taylorotwell
Copy link
Member

I think it's OK as is. Kind of a mouthful as one method.

@eusonlito
Copy link
Contributor Author

Okey then :)

@eusonlito eusonlito deleted the patch-1 branch January 15, 2020 13:33
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

2 participants