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.

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
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
Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate logo

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate

Build your SaaS application in hours. Out-of-the-box multi-tenancy and seamless Stripe integration. Supports subscriptions and one-time purchases, allowing you to focus on building and creating without repetitive setup tasks.

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate
Rector logo

Rector

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

Rector
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 →
Asymmetric Property Visibility in PHP 8.4 image

Asymmetric Property Visibility in PHP 8.4

Read article
Access Laravel Pulse Data as a JSON API image

Access Laravel Pulse Data as a JSON API

Read article
Laravel Forge adds Statamic Integration image

Laravel Forge adds Statamic Integration

Read article
Transform Data into Type-safe DTOs with this PHP Package image

Transform Data into Type-safe DTOs with this PHP Package

Read article
PHPxWorld - The resurgence of PHP meet-ups with Chris Morrell image

PHPxWorld - The resurgence of PHP meet-ups with Chris Morrell

Read article
Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3 image

Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3

Read article