Your code isn't showing, but I'm suspecting that it has something to do with your validation rules for the date. It's expecting it in a format that it isn't being sent from the form.
Apr 9, 2018
28
Level 3
The date does not match the format d F Y - H:i.
Im getting this errror when updating a post:
The date does not match the format d F Y - H:i.
Do you know where is the issue?
input html:
<div class="form-group col-md-6">
<label for="date">Date</label>
<div class="input-group date" data-provide="datepicker">
<input type='text' onkeydown="event.preventDefaultdate
name="date" value="{{old('registration_type_start_date')}}"
class="form-control" placeholder="DD/MM/YYY" />
<span class="input-group-addon"><i class="fa fa-calendar text-primary" aria-hidden="true"></i></span>
</div>
</div>
jQuery:
$( ".input-group.date" ).datetimepicker({
format: "dd MM yyyy - hh:ii",
autoclose: true,
todayBtn: true,
minuteStep: 5
});
update method:
public function update(Request $request, $id){
$this->validate($request, [
....
'date' => 'required|date_format:d F Y - H:i',
]);
$post->date = Carbon::createFromFormat('d F Y - H:i', $request->date);
$post->save();
return redirect()->back();
}
Level 67
Yes, convert it to how you want to show it on the front end.
{{ $something->date->format('d F Y - H:i') }}
So try changing this:
$( ".input-group.date" ).datetimepicker({
format: "YYYY-MM-DD HH:mm:ss",
autoclose: true,
todayBtn: true,
minuteStep: 5
});
And then use
$this->validate($request, [
....
'date' => 'required|date',
]);
$post->save();
return redirect()->back();
Note: in order to change the format when displaying it, it needs to be a carbon instance. So you should include date as a $date mutator in your model.
https://laravel.com/docs/5.6/eloquent-mutators#date-mutators
1 like
Please or to participate in this conversation.