Model Date Mutators - an easier way

Submitted by meigwilym - 10 years ago

Laravel's docs suggest to override the Model's getDates() methods when adding your own date fields. http://laravel.com/docs/4.2/eloquent#date-mutators To keep the default created_at, updated_at and deleted_at date fields, these must also be returned by the method, giving you at least 4 elements to the array. An easier (or at least, tidier) way is to set the protected $dates property with your own fields. These are merged with the defaults.

protected $dates = ['pub_date', 'birthday']; // etc