Answer the question
In order to leave comments, you need to log in
Write datetime-local format date to db?
Hello. It is necessary to record the date in a database of a certain format.
There is a text field
<input name="date_start" value="{{ isset($editEvent) ? $editEvent->date_start->format('Y-m-d\TH:i') : '' }}" type="datetime-local" class="form-control" required>
protected $dates = ['date_start'];
$editEvent = $eventModel::find($id);
$editEvent->update($request->all());
protected $dateFormat = 'Y-m-d\TH:i';
Answer the question
In order to leave comments, you need to log in
Remove $dateFormat from the class. Add to model
public function setDateStartAttribute($value)
{
$this->attributes['date_start'] = Carbon::createFromFormat('Y-m-d\TH:i', $value);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question