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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners