amitshahc
4 months ago

Model::create($data) with Carbon dates fields in $data returns Carbon object.

Posted 4 months ago by amitshahc

In my case, using observer, I am trying to save a model object in json format on both events of Create, Update.

  1. When i get $record = $model::create($data); the $record->start_time field remains a Carbon object.
  2. but while updating i fetch that $record using $record = model::find($id); and the $record->start_time is string date format.

Ideally it should be the same in both case and should be string data format.

Why the difference? how to resolve it?

Please sign in or create an account to participate in this conversation.