Laravel 8.16 Released

Published on by

Laravel 8.16 Released image

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 for callSilent() (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)
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 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
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 →
Add Comments to your Laravel Application with the Commenter Package image

Add Comments to your Laravel Application with the Commenter Package

Read article
Laravel Advanced String Package image

Laravel Advanced String Package

Read article
Take the Annual State of Laravel 2024 Survey image

Take the Annual State of Laravel 2024 Survey

Read article
Upload Files Using Filepond in Livewire Components image

Upload Files Using Filepond in Livewire Components

Read article
The Best Laravel Tutorials and Resources for Developers image

The Best Laravel Tutorials and Resources for Developers

Read article
Introducing Built with Laravel image

Introducing Built with Laravel

Read article