Laravel 8.10 Released

Laravel 8.10 Released

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)

Filed in: News / Laravel 8

Newsletter

Join 31,000+ others and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior Laravel Developer
Remote
EC Pro
Senior Full-Stack Engineer
[REMOTE: USA Only] All Other Applications Will be Rejected Immediately"
Curricula
Senior Full Stack PHP Developer
Canada
Motto Design Studio
Software Engineer
Remote, USA Only
Grow Progress
Lead Backend PHP Developer
Hamburg, Deutschland
ABOUT YOU GmbH