Immutable dates and casting to them

Laravel 8.53 introduces the immutable_date and immutable_datetime castes that convert dates to Immutable.

Cast to CarbonImmutable instead of a regular Carbon instance.

1class User extends Model
2{
3 public $casts = [
4 'date_field' => 'immutable_date',
5 'datetime_field' => 'immutable_datetime',
6 ];
7}

Tip given by @PascalBaljet

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord