I was looking for the same thing, but unfortunately I could not create a way to create global access.
The βproblemβ with the dateFormat property is that it is a mutator, not an accessory. The extension of the base class does not work both for the user model and for other models, since it extends Authenticatable, and not the model directly.
Here's what I did as the next best - I created the FormatsDates . Using your methods:
trait FormatsDates { protected $newDateFormat = 'dmY H:i:s'; public function getUpdatedAtAttribute($value) { return Carbon::parse($value)->format($this->newDateFormat); } public function getCreatedAtAttribute($value) { return Carbon::parse($value)->format($this->newDateFormat); } }
Now I can use this trait for any model I want. e.g. User Model:
class User extends Authenticatable { use FormatsDates; }
Maybe someone will find this useful.
source share