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

[8.x] Adds the valueOfFail() Eloquent builder method #38707

merged 1 commit into from Sep 8, 2021

[8.x] Adds the valueOfFail() Eloquent builder method #38707

merged 1 commit into from Sep 8, 2021


Copy link

@DarkGhostHunter DarkGhostHunter commented Sep 7, 2021


It's the same value() but it will fail miserably if the model is not found.

// Before:
$votes = User::where('name', 'John')->firstOrFail('votes')->votes;

// Now:
$votes = User::where('name', 'John')->valueOrFail('votes');

This is miles better if model contains properties that can be null.


It just copy-pastes the value() method but instead uses firstOrFail() and removes the condition since the model is expected to exist.


None, it's additive.


  • I decided to not include valueOr() since you can use ?? or ??=, which are awesome.

@taylorotwell taylorotwell merged commit d73de59 into laravel:8.x Sep 8, 2021
victorvilella pushed a commit to cdsistemas/framework that referenced this pull request Oct 12, 2021
@DarkGhostHunter DarkGhostHunter deleted the feat/value-or-fail-2 branch November 25, 2021 04:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants