Sorry I didnt notice the previous answer. And yes you are right:
<form method="post" action="{{route('viewing.store')}}">
@csrf
<input type="hidden" name="property_id" value="{{$property->id}}">
@foreach ($days as $dayName => $dayAbbr)
<div class="flddex">
<label class="day">{{ $dayName }}</label>
<input type="checkbox" name="day[{{ $dayAbbr }}]" value="{{ $dayAbbr }}">
<label>From</label>
<input type="text" class="timepicker form-cont" name="from[{{ $dayAbbr }}]"></input>
<label>To</label>
<input type="text" class="timepicker form-cont" name="to[{{ $dayAbbr }}]"></input>
</div>
@endforeach
<button type="submit" class="btn1-primary btn1">Add</button>
</form>
In the controller:
$days = $request->day;
$froms = $request->from;
$tos = $request->to;
if (count($days)) {
foreach ($days as $key => $day) {
Viewingdate::create([
'property_id' => $request->property_id,
'day' => $day,
'from' => $froms[$key],
'to' => $tos[$key],
]);
}
}
It saves one record at the time. If I try select multiple rows then it gives integrity contraint error:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'from_time' cannot be null (SQL: insert into `viewingdates` (`property_id`, `day`, `from_time`, `to_time`, `updated_at`, `created_at`) values (21, Tue, , , 2018-09-26 20:17:26, 2018-09-26 20:17:26))