Laravel 8.58 Released


September 1st, 2021


The Laravel team released 8.58 with a updateOrFail() Eloquent method, two new validation rules, and the latest changes in the v8.x branch.

Laravel technically added some features in v8.57, but we have another release this week, so we'll cover the highlights from both:

Update or Fail Method (8.58)

Claas Augner contributed an updateOrFail() method to Eloquent which makes it more convenient to handle update errors in update actions. It relies on saveOrFail() which saves a model to the database using a transaction (PR #11202):

1try {
2 $device->updateOrFail();
3} catch (Exception $e) {
4 return false;

Exclude Validation Rule (8.57)

@bastien-phi contributed an exclude validation rule, which will exclude the field from validated data. A typical use-case would likely be the default from a conditional validation rule:

1public function rules()
3 return [
4 'role' => ['required', 'in:user,guest'],
5 'email' => Rule::when(
6 function ($data) => $data->get('role') === 'user',
7 ['required', 'string', 'email'],
8 'exclude'
9 ),
10 ];

Passing a Callback with HTTP Retry (8.57)

Daniel Mason contributed the ability to pass a callback to the HTTP client retry method which determines if the client should actually retry:

1$response = Http::retry(3, 100, function ($exception) {
2 return $exception instanceof ConnectionException;

Shortcut for Simple "Where" Relationship Queries (8.57)

@Italo contributed a whereRelation method for simple where clauses in Eloquent queries:

1// Before:
2User::whereHas('posts', function ($query) {
3 $query->where('published_at', '>', now());
6// After
7User::whereRelation('posts', 'published_at', '>', now())->get();

Prohibits Validation Rule

Samuel Levy contributed the prohibits validation rule where a validator could pass two potential fields, but if one exists, the other cannot:

2 'post_id' => 1,
3 'created_by' => 2,
4 'created_at' => '2020-07-16 20:54:22'
5], [
6 'post_id' => 'prohibits:created_by,created_at'

Release Notes

You can see the complete list of new features and updates below and the diff between 8.57.0 and 8.58.0 on GitHub. This post also includes some highlights from 8.57—check out 8.56.0 and 8.57.0.

The following release notes are directly from the changelog:



  • Added updateOrFail method to Model (#38592)
  • Make mail stubs more configurable (#38596)
  • Added prohibits validation (#38612)




  • Added exclude validation rule (#38537)
  • Allow passing when callback to Http client retry method (#38531)
  • Added Illuminate/Testing/TestResponse::assertUnprocessable() (#38553)
  • Added the password reset URL to the toMailCallback (#38552)
  • Added a simple where helper for querying relations (#38499)
  • Allow sync broadcast via method (#38557)
  • Make $validator->sometimes() item aware to be able to work with nested arrays (#38443)


  • Fixed Blade component falsy slots (#38546)
  • Keep backward compatibility with custom ciphers in Illuminate/Encryption/Encrypter::generateKey() (#38556)
  • Fixed bug discarding input fields with empty validation rules (#38563)


  • Don't iterate over all collection in Collection::firstOrFail (#38536)
  • Error out when detecting incompatible DBAL version (#38543)

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.