My take:
Assumptions: A break has to be between a the work_from and work_to values, and that a break is non-optional.
As far as organizing inputs, I would create nested form fields for each day, like so:
times[monday[work_from]]
times[monday[work_to]]
times[monday[break_from]]
times[monday[break_to]]
Repeat for each day of the week.
When the user submits, you need to turn that data into 3 models per work day. So something like this:
$timeRangesByDay = $request->get('times')
foreach($timeRangesByDay as $dayOfWeek => $timeRanges) {
$preBreakHours = [
$timeRanges['work_from'],
$timeRanges['break_from']
];
$breakHours = [
$timeRanges['break_from'],
$timeRanges['break_to']
];
$postBreakHours = [
$timeRanges['break_to'],
$timeRanges['work_to']
];
//left as an exercise for the reader ;)
$this->businessHoursValidator->validate($preBreakHours, $breakHours, $postBreakHours);
$this->businessHoursService->createForDay($dayOfWeek, $preBreakHours, $breakHours, $postBreakHours);
}
And the service class is pretty simple:
public function createForDay($dayOfWeek, array $preBreakHours, array $breakHours, array $postBreakHours)
{
$user = $this->auth->user();
$dayId = $this->getDayIdFromString($dayOfWeek);
$preBreak = $this->createHoursInstance($user, $dayId, $preBreakHours[0], $preBreakHours[1]);
$break = $this->createHoursInstance($user, $dayId, $breakHours[0], $breakHours[1], true);
$postBreak = $this->createHoursInstance($user, $dayId, $postBreakHours[0], $postBreakHours[1]);
return compact('preBreak', 'break', 'postBreak');
}
public function createHoursInstance(User $user, $dayId, $startTime, $endTime, $isBreak = false)
{
return BusinessHours::create([
'user_id' => $user->getKey(),
'weekDay' => $dayId,
'start_time' => $startTime,
'end_time' => $endTime,
'is_break' => (int) $isBreak
]);
}
That should be plenty to get you started.
EDIT: @martinbean has the right idea, you should store the two non-break date range and assume anything else means closed.