@IFGroup how would that work? When creating "2015-4-2 12:00:00" to integer, what should be returned?
Apr 2, 2015
4
Level 1
Eloquent date to int.
How to convert eloquent DateTime attributes to int?
Level 56
I will assume that by converting to int you mean getting the unix timestamp.
$timestamp = $user->created_at->timestamp
created_at and updated_at are automatically converted to Carbon instances by Eloquent. See Carbon as a DateTime on steroids [ https://github.com/briannesbitt/Carbon ].
If you need other fields in your model to be treated like that by Eloquent take a look in the docs [ http://laravel.com/docs/5.0/eloquent#date-mutators ]. Basically you should override the getDates(...) method
public function getDates()
{
return ['created_at', 'my_date'];
}
2 likes
Please or to participate in this conversation.