Improved single-method accessors and mutators in Laravel 8.x

1 · Amit Merchant · Dec. 27, 2021, 10:21 a.m.
When you want to format certain Eloquent models before setting/retrieving in Laravel, you would certainly reach for the accessors and mutators. Old Accessors & Mutators The problem Improved Accessors & Mutator It’s even better with PHP 8 I have already discussed this in detail in one of the posts. But if I have to give a summary of this, I’ll explain it with an example. Old Accessors & Mutators So, let’s say we have a tax field called tax in our table and if I want to set the computed ta...