I'm running into an odd validation problem in Laravel 4 & Carbon.
I have a form that has some required general fields at the top (a couple of drop-downs and a text field), then a series of date & time fields that are not required.
I have a validator set up to have the first 3 fields required, and the date/time fields set to 'date_format:Y-m-d H:i' (seconds are not important here).
The "airline_open", "airline_close", "hotel_open", "hotel_close" fields below are the ones causing the problems.
As long as the required fields are filled in, everything works great. If the required fields are not filled in, and there are no date/time fields filled in, also great (I get appropriate messaging). However, if any of the required fields are not filled in, and any of the date/time fields are filled in with the expected format (no seconds), I get an exception thrown by Carbon. (Interestingly, if I include the seconds for the time, it doesn't thrown the exception, but gives the validation error.)
This exception seems to be similar to this problem: Laravel Carbon Data Missing
However, given that everything works as designed as long as the required fields are filled in, it feels like I should be able to make this work without having to mess around with Carbon's date format.
Any ideas?
Adding some code:
Validator:
'direction' => 'required',
'type' => 'required',
'notes' => 'required',
'callback_time' => 'date_format:H:i',
'callback_time2' => 'required_if:callback_type, 4|date_format:H:i',
'airline_open' => 'date_format:Y-m-d H:i',
'airline_close' => 'date_format:Y-m-d H:i',
'hotel_open' => 'date_format:Y-m-d H:i',
'hotel_close' => 'date_format:Y-m-d H:i'
);
From the form (the airline_open & airline_close fields). The "now" button calls some js to populate the field with the date & time in the desired format:
<tr class="airline-reservation @if ($data->airline_reservation == 0) _hide @endif">
<td width="25%">{{ trans('nationalbank.call.form.open') }}:</td>
<td width="25%">
<input type="text" class="form-control" name="airline_open" id="airline_open" @if ($data->airline_open > 0)) value="{{ Carbon\Carbon::createFromFormat('Y-m-d H:i:s',$data->airline_open)->format('Y-m-d H:i') }}" @endif size="30">
<a href="javascript:;" class="btn btn-info btn-xs nowbtn" id="now-airline_open">now</a>
</td>
<td width="25%">{{ trans('nationalbank.call.form.close') }}:</td>
<td width="25%">
<input type="text" class="form-control" name="airline_close" id="airline_close" @if ($data->airline_close > 0)) value="{{ Carbon\Carbon::createFromFormat('Y-m-d H:i:s',$data->airline_close)->format('Y-m-d H:i') }}" @endif size="30">
<a href="javascript:;" class="btn btn-info btn-xs nowbtn" id="now-airline_close">now</a>
</td>
</tr>