Immutable Date Casting in Laravel 8.53
Published on by Paul Redmond
The Laravel team released 8.53 with immutable date and datetime casting, a queue monitoring command, and the latest changes in the 8.x branch:
Immutable Date and Datetime Casting
Adam Campbell contributed two new model casts: immutable_date
and immutable_datetime
. It maintains support for all current date/datetime functionality, except it returns a CarbonImmutable
instance instead of Carbon
.
I recently got into the habit of using CarbonImmutable in parts of my apps instead of Carbon, especially when juggling timestamps across time zones.
— Adam Campbell (@hotmeteor) August 1, 2021
With that in mind, I created a Laravel PR to allow for casting date and datetime values to immutable: https://t.co/cVSnYqivyo
Check out Pull Request #38199 for further details on the implementation. To get started with date casts, check out the Date Casting documentation.
Queue Monitoring Artisan Command
Mohamed Said contributed a new queue:monitor
artisan command that will check the sizes of all queues provided and output them in a console:
A twiceDailyAt Scheduler Method
Doug Sisk contributed a twiceDailyAt
scheduler frequency that allows setting the specific minutes past an hour to run at:
$schedule ->command('example:command') ->twiceDailyAt(first: 2, second: 14, offset: 5);
"Accepted If" Validation Rule
Anees Khan contributed an accepted_if
validation rule, which means a field must be "truthy" if another field under validation is equal to a specific value. This is useful for validating terms of service or other similar confirmation flows:
$v = new Validator( $trans, [ 'foo' => 'true', 'bar' => 'aaa' ], [ 'foo' => 'accepted_if:bar,aaa' ]); $this->assertTrue($v->passes());
Release Video
Release Notes
You can see the full list of new features and updates below and the diff between 8.52.0 and 8.53.0 on GitHub.