Performance: Accessors and mutators
MEDIUM IMPACT
Accessors and mutators affect how data is transformed before rendering or saving, impacting server response time and client rendering speed.
protected $appends = ['full_name']; public function getFullNameAttribute() { return strtoupper($this->first_name) . ' ' . strtoupper($this->last_name); } // Use caching or eager loading when possible
public function getFullNameAttribute() {
return strtoupper($this->first_name) . ' ' . strtoupper($this->last_name);
}
// Called multiple times in a loop or view without caching| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy accessor logic called repeatedly | N/A | N/A | Increases server response time delaying paint | [X] Bad |
| Accessor with cached/computed once per instance | N/A | N/A | Faster server response, quicker paint | [OK] Good |