0

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.

1 Answer 1

2

Ok, I managed to have that working.

I needed to parse given date before saving

Carbon::parse($request->input('start_date'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.