Here we will see how we can add a new attribute in an eloquent model. Sometimes When converting models to arrays or JSON,we require additional information based on some calculation/manipulation on columns of models, in that case we can easily add this new attribute in model using following steps provided by Laravel. Suppose we have an user model and we want a full_name attribute to be appended for the user. As first_name and last_name already exist in database as columns ,we can easily create fullname as following: Define https://laravel.com/docs/9.x/eloquent-mutators : first_name.

So here comes the next step : Add attribute to Append property:
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners