Laravel 8.10 Released

Published on by

Laravel 8.10 Released image

The Laravel team released 8.10 this week with job chains within batches, database upserts, and the latest new features, fixes, and changes in the 8.x branch.

Job Chains in Batches

Kevin Ullyott contributed job chaining within batches. You can add chaining by passing a sub-array of job classes like so:

$batch = Bus::batch([
new Test1Job(),
[
new Test2Job(),
new Test3Job(),
new Test4Job(),
]
])->then(function (Batch $batch) {
Log::info('Test Complete!');
})->name('Test')->dispatch();

Add is() Method to Model Relations

Sébastien Nikolaou contributed the is() and isNot() methods to Eloquent relations without an extra query:

// Before: performs extra query to fetch the user model from the author relation
$post->author->is($user);
$post->author->isNot($user);
 
// After
$post->author()->is($user);
$post->author()->isNot($user);

Add Upsert to Eloquent and Query Builder

Paras Malhotra contributed upserting records, which will bulk insert records and update those with duplicate keys. The first argument is the data to be inserted/updated, and the second argument is the column(s) that uniquely identify a given record:

DB::table('users')->upsert([
['id' => 1, 'email' => 'taylor@example.com'],
['id' => 2, 'email' => 'dayle@example.com'],
], 'email');
 
// Or with models
User::upsert([
['id' => 1, 'email' => 'taylor@example.com'],
['id' => 2, 'email' => 'dayle@example.com'],
], 'email');

A newline method for console IO

Scott Carpenter contributed a newLine() method you can use to output a blank line in Artisan console output:

// What you might do now...
$this->info('');
$this->info('Parsing CSV file');
$this->info('');
 
// You could already do the following
$this->getOutput()->newLine();
 
// This feature adds a shortcut
$this->newLine();
 
// You can specify the number of blank lines
$this->newLine(5);

A canAny() Method for Authorizable Models

Denis Duliçi contributed a canAny method to the Authorizable trait that the User model supports. This allows the following (similar to the blade feature with the same name):

$user->canAny(['permission-one', 'permission-two'])

MailMessage when() and unless() Methods

Kuba Szymanowski contributed new convenience methods to the MailMessage class for when you want to change the mail message conditionally:

public function toMail(User $user)
{
return (new MailMessage)
->when(
$this->offer->acceptation_comment,
function(MailMessage $message, $comment) {
$message->line('Your offer has been rejected with a comment:')
->line($comment);
},
function(MailMessage $message) {
$message->line('Your offer has been rejected.');
}
);
}

Release Notes

You can see the full list of new features and updates below and the diff between 8.9.0 and 8.10.0 on GitHub. The following release notes are directly from the changelog:

8.10.0

Added

  • Allow for chains to be added to batches (#34612, 7b4a9ec)
  • Added is() method to 1-1 relations for model comparison (#34693, 7ba2577)
  • Added upsert to Eloquent and Base Query Builders (#34698, #34712, 58a0e1b)
  • Support psql and pg_restore commands in schema load (#34711)
  • Added Illuminate\Database\Schema\Builder::dropColumns() method on the schema class (#34720)
  • Added yearlyOn() method to scheduler (#34728)
  • Added restrictOnDelete method to ForeignKeyDefinition class (#34752)
  • Added newLine() method to InteractsWithIO trait (#34754)
  • Added isNotEmpty method to HtmlString (#34774)
  • Added delay() to PendingChain (#34789)
  • Added ‘multiple_of’ validation rule (#34788)
  • Added custom methods proxy support for jobs ::dispatch() (#34781)
  • Added QueryBuilder::clone() (#34780)
  • Support bus chain on fake (a952ac24)
  • Added missing force flag to queue:clear command (#34809)
  • Added dropConstrainedForeignId to `Blueprint (#34806)
  • Implement supportsTags() on the Cache Repository (#34820)
  • Added canAny to user model (#34815)
  • Added when() and unless() methods to MailMessage (#34814)

Fixed

  • Fixed collection wrapping in BelongsToManyRelationship (9245807)
  • Fixed LengthAwarePaginator translations issue (#34714)

Changed

  • Improve schedule:work command (#34736, bbddba2)
  • Guard against invalid guard in make:policy (#34792)
  • Fixed router inconsistency for namespaced route groups (#34793)
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
No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project.

Visit No Compromises
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
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $7500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
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
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
LoadForge logo

LoadForge

Easy, affordable load testing and stress tests for websites, APIs and databases.

LoadForge
Paragraph logo

Paragraph

Manage your Laravel app as if it was a CMS – edit any text on any page or in any email without touching Blade or language files.

Paragraph
Lucky Media logo

Lucky Media

Bespoke software solutions built for your business. We ♥ Laravel

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
DocuWriter.ai logo

DocuWriter.ai

Save hours of manually writing Code Documentation, Comments & DocBlocks, Test suites and Refactoring.

DocuWriter.ai
Rector logo

Rector

Your partner for seamless Laravel upgrades, cutting costs, and accelerating innovation for successful companies

Rector

The latest

View all →
Non-backed Enums in Database Queries and a withSchedule() bootstrap method in Laravel 11.1 image

Non-backed Enums in Database Queries and a withSchedule() bootstrap method in Laravel 11.1

Read article
Laravel Pint --bail Flag image

Laravel Pint --bail Flag

Read article
Laravel Herd for Windows is now released! image

Laravel Herd for Windows is now released!

Read article
The Laravel Worldwide Meetup is Today image

The Laravel Worldwide Meetup is Today

Read article
Cache Routes with Cloudflare in Laravel image

Cache Routes with Cloudflare in Laravel

Read article
Learn how to manage timezones in your Laravel Apps image

Learn how to manage timezones in your Laravel Apps

Read article