Reputation: 167
I have a model with a created_at
value defined as a Unix timestamp.
I retrieve an instance of my model with $model = Model::where(...)->first()
When I var_dump($model->created_at)
I get a Illuminate\Support\Carbon
instance instead of my integer timestamp.
According to the documentation (emphasis mine):
By default, Eloquent will convert the created_at and updated_at columns to instances of Carbon, which extends the PHP DateTime class to provide an assortment of helpful methods. You may customize which dates are automatically mutated, and even completely disable this mutation, by overriding the $dates property of your model
I've tried adding protected $dates = []
to my model, but I still get the Carbon
object instead of an integer.
If I disable timestamps (public $timestamps = false;
) it works, but then I won't get my timestamp inserted when I create new entries - and I need that.
Upvotes: 1
Views: 1090
Reputation: 14278
Have you tried using:
protected $casts = [
'created_at' => 'integer'
];
Upvotes: 0