Reputation: 4161
I created new date
field called start_date
, and I also have two columns for created_at
and updated_at
which are defined as timestamp
.
In my model I have following line, that should tell Laravel to treat these columns as Carbon objects.
protected $dates = ['created_at', 'updated_at', 'start_date']
.
In received request, start_date is stored like this:
2015-10-28T10:37:31.337Z
, and when I try to save it, I got following error:
InvalidArgumentException in Carbon.php line 414:
Unexpected data found.
Trailing data
in Carbon.php line 414
at Carbon::createFromFormat('Y-m-d H:i:s', '2015-10-28T10:37:31.337Z') in Model.php line 2925
I tried several things, including changing dateFormat
on Model, changing format on property before saving model, but I keep receiving same error.
What is supposed way to handle situations like this? Can I have different types of columns handled by Carbon? Do I need to change it change format for them manually? I checked docs, but I couldn't find anything regarding that.
Upvotes: 0
Views: 3518
Reputation: 4161
Ok, I managed to have that working.
I needed to parse given date before saving
Carbon::parse($request->input('start_date'));
Upvotes: 2