Source: medium.com

Laravel Custom Cast

Category: Laravel

One of the new features in Laravel 7 is the creation of custom eloquent casts. These provide the majority of use cases for allowing you to change the value of the attribute on the way into the database and on the way out.Alternatively, if you want to change the value of the attributes you can use mutator getter and setter methods. When eloquent attempts to fill the model it will use these mutator attributes to change the value of the attributes on the way in and out of the database. The downside of this approach is that it populates the model class which can grow larger and harder to manage.

Set is used when saving the model in the database we can take the date value and convert it to UTC.
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