Laravel Idea for PhpStorm - Full-featured IDE for productive artisans!

Laravel 8.58 Released

Published on by

Laravel 8.58 Released image

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):

try {
$device->updateOrFail();
} catch (Exception $e) {
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:

public function rules()
{
return [
'role' => ['required', 'in:user,guest'],
'email' => Rule::when(
function ($data) => $data->get('role') === 'user',
['required', 'string', 'email'],
'exclude'
),
];
}

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:

$response = Http::retry(3, 100, function ($exception) {
return $exception instanceof ConnectionException;
})->post(...);

Shortcut for Simple "Where" Relationship Queries (8.57)

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

// Before:
User::whereHas('posts', function ($query) {
$query->where('published_at', '>', now());
})->get();
 
// After
User::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:

Validator::validate([
'post_id' => 1,
'created_by' => 2,
'created_at' => '2020-07-16 20:54:22'
], [
'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:

v8.58.0

Added

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

Changed

v8.57.0

Added

  • 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

  • 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)

Changed

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

Staff writer at Laravel News. Full stack web developer and author.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Bacancy

Outsource a dedicated Laravel developer for $2,500/month. With over a decade of experience in Laravel development, we deliver fast, high-quality, and cost-effective solutions at affordable rates.

Visit Bacancy
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $2500/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Laravel Forge logo

Laravel Forge

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Forge
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Cut PHP Code Review Time & Bugs into Half with CodeRabbit logo

Cut PHP Code Review Time & Bugs into Half with CodeRabbit

CodeRabbit is an AI-powered code review tool that specializes in PHP and Laravel, running PHPStan and offering automated PR analysis, security checks, and custom review features while remaining free for open-source projects.

Cut PHP Code Review Time & Bugs into Half with CodeRabbit
Join the Mastering Laravel community logo

Join the Mastering Laravel community

Connect with experienced developers in a friendly, noise-free environment. Get insights, share ideas, and find support for your coding challenges. Join us today and elevate your Laravel skills!

Join the Mastering Laravel community
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
LaraJobs logo

LaraJobs

The official Laravel job board

LaraJobs
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
MongoDB logo

MongoDB

Enhance your PHP applications with the powerful integration of MongoDB and Laravel, empowering developers to build applications with ease and efficiency. Support transactional, search, analytics and mobile use cases while using the familiar Eloquent APIs. Discover how MongoDB's flexible, modern database can transform your Laravel applications.

MongoDB

The latest

View all →
Laravel Simple RabbitMQ Package image

Laravel Simple RabbitMQ Package

Read article
Navigating Dates Elegantly with Carbon in Laravel image

Navigating Dates Elegantly with Carbon in Laravel

Read article
Memoized Cache Driver in Laravel 12.9 image

Memoized Cache Driver in Laravel 12.9

Read article
Laravel Cookie Consent image

Laravel Cookie Consent

Read article
Converting Non-Decimal Strings with Laravel's Enhanced toInteger() Method image

Converting Non-Decimal Strings with Laravel's Enhanced toInteger() Method

Read article
Herd Xdebug Toggler for Visual Studio Code image

Herd Xdebug Toggler for Visual Studio Code

Read article