Unlock Your Python Backend Career: Build 30 Projects in 30 Days. Join now for just $54

LATEST laravel-model ARTICLES

Latest laravel-model Articles curated daily by the community.

How to Mutate Eloquent Model Attributes

By Eric McWinNEr · Updated Sun Jun 18 2023

This article will explain the different ways to automatically manipulate and mutate eloquent model attributes while accessing or retrieving them. 

There are many times when it’s necessary to do computations or add extra attributes based on existing attributes on an eloquent model. 

An excellent example of this could be concatenating the first name (first_name) and last name (last_name) of the user to form a new computed attribute called name that didn’t exist on our model in the first place. 

How to Mutate Eloquent Model Attributes

Another example could be prepending the host/app URL that points to stored files in our database during retrieval.