Laravel 8.16 Released
Published on by Paul Redmond
The Laravel team released 8.16 last week with an artisan command to take you directly to a database CLI, an excellent progress bar convenience method, and a new Ably broadcaster implementation.
This release was jam-packed with awesome new features, so let’s check out the latest changes in the 8.x branch:
With Progress Bar Convenience Method
Taylor Otwell contributed the withProgressBar()
convenience method you can use in console commands. Here’s what you might do to create a progress bar straight from the docs:
$users = App\Models\User::all();$bar = $this->output->createProgressBar(count($users)); $bar->start(); foreach ($users as $user) { $this->performTask($user); $bar->advance();} $bar->finish();
With this convenience method, it could look like this:
$users = App\Models\User::all(); $this->withProgressBar($users, function ($user, $bar) { $this->performTask($user);});
Call Silently
Taylor Otwell contributed a callSilently()
method which is an alias to callSilent
in the CallsCommands
trait. You might find that this reads more clearly:
$this->callSilently('config:cache');
Release Unique Job Locks Before Processing
Paras Malhotra contributed the ability to release unique job locks before the job processes. The new interface is useful for scenarios where a race condition could exist between job completion and unlocking. To learn more, I’d suggest checking out Pull Request #35255 to the framework and the documentation pull request.
Ably Broadcaster
Taylor Otwell contributed an AblyBroadcaster
for broadcasting real-time, live-updating user interfaces. Developers can now pick from Pusher, Redis, and Ably for real-time communication needs. For a refresher, check out the Broadcasting documentation on how you can get started broadcasting in your Laravel projects.
Support Delaying Notifications Per Channel
Gergő D. Nagy contributed the ability to delay notification delivery on a per-channel basis instead of one overall delay. Defining delays per channel is useful if you need to delay the same notification differently for email, database, SMS, etc., notifications. You may now optionally call delay()
with an associative array of channels you’d like to delay:
$user->notify((new InvoicePaid($invoice))->delay([ 'mail' => now()->addMinutes(5), 'sms' => now()->addMinutes(10),]));
Note that a channel not defined in the array will not have a delay when using the array format.
Allow Array Sorting By Multiple Criteria
johnylemon contributed a sortByMany
method to the Arr
support class, which will sort props in ascending order by default:
$sorted = Arr::sortByMany($unsorted, [ 'name', 'age']; $sorted = Arr::sortByMany($unsorted, [ ['name', false], // will be ordered by `name` descending ['age', true] // then by age ascending, if there are items with same `name` value];
Lastly, the PR outlines complex sorting using closures:
$sorted = Arr::sortByMany($unsorted, [ // order by childrens count asc function($a, $b) { return $a->childrens()->count() <=> $b->childrens()->count(); }, // then by grandchildrens by descending order if needed function($a, $b) { return $b->grandchildrens()->count() <=> $a->grandchildrens()->count(); }];
Drop Into a Database CLI
Paras Malhotra—who has been contributing a lot of excellent queue features lately—contributed a new artisan command to drop into a database CLI:
php artisan db mysql
The above command will use the database credentials to connect to a MySQL CLI prompt without manually remembering/alias commands. This command should work with mysql
, pgsql
, sqlite
, and sqlsrv
.
Collections splitIn Method
Andrew Brown contributed the splitIn
method, which is similar to split. The distinct difference is that split
makes it so that each chunk never differs in count from another chunk by more than one. Conversely, splitIn
will fill all earlier chunks before allocating the remainder to the final chunk. The pull request has further details on why you might use splitIn
if you’d like to learn more.
Release Notes
You can see the full list of new features and updates below and the diff between 8.15.0 and 8.16.0 on GitHub. The following release notes are directly from the changelog:
v8.16.0
Added
- Added
Illuminate\Console\Concerns\InteractsWithIO::withProgressBar()
(4e52a60, 169fd2b) - Added
Illuminate\Console\Concerns\CallsCommands::callSilently()
as alias forcallSilent()
(7f3101b, 0294433) - Added option to release unique job locks before processing (#35255, b53f13e)
- Added ably broadcaster (e0f3f8e, 6381aa9)
- Added ability to define table name as default morph type (#35257)
- Allow overriding the MySQL server version for database queue driver (#35263)
- Added
Illuminate\Foundation\Testing\Wormhole::back()
(#35261) - Support delaying notifications per channel (#35273)
- Allow sorting on multiple criteria (#35277, 53eb307)
- Added
Illuminate/Database/Console/DbCommand.php
command (#35304, b559b3e) - Added Collections
splitIn
methods (#35295)
Fixed
- Fixed rendering of notifications with config custom theme (325a335)
- Fixing BroadcastException message in PusherBroadcaster@broadcast (#35290)
- Fixed generic DetectsLostConnection string (#35323)
- Fixed SQL Server command generation (#35317)
- Fixed route model binding on cached closure routes (eb3e262)
Changed
- Disable CSRF on broadcast route (acb4b77)
- Easily set a null cache driver (#35262)
- Updated
aws/aws-sdk-php
suggest to^3.155
(#35267) - Ensure ShouldBeUniqueUntilProcessing job lock is released once (#35270)
- Rename qualifyColumn to qualifyPivotColumn in BelongsToMany & MorphToMany (#35276)
- Check if AsPivot trait is used instead of Pivot Model in
Illuminate\Database\Eloquent\Relations\BelongsToMany
(#35271) - Avoid no-op database query in Model::destroy() with empty ids (#35294)
- Use –no-owner and –no-acl with pg_restore (#35309)