Accessor Caching

As of Laravel 9.6, if you have a computationally intensive accessor, you can use the shouldCache method.

1public function hash(): Attribute
2{
3 return Attribute::make(
4 get: fn($value) => bcrypt(gzuncompress($value)),
5 )->shouldCache();
6}

Tip given by @cosmeescobedo

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