public function postAddHoursEmployee(Request $request) { $planning = new Planning(); $planning->user_id = Auth::user()->id; $planning->date = Carbon::today()->format('Y-m-d'); $planning->from = $request->start; $planning->break = $request->pauze; $planning->untill = $request->end; $planning->status = 3; $planning->save(); return redirect('myschedule'); }
/** * Execute the console command. * * @return mixed */ public function handle() { $today = Carbon::today(); $nextMonth = Carbon::today()->addMonth(); $monday = new Carbon('next monday'); $sunday = new Carbon('next monday'); $sunday->addDays(6); echo $sunday; $planningen = Planning::where('first_day', '>', $today)->get(); var_dump($planningen); while ($monday < $nextMonth) { $not_exists = true; foreach ($planningen as $planning) { if ($monday >= $planning->first_day && $monday <= $planning->last_day) { $not_exists = false; } } if ($not_exists) { $newPlanning = new Planning(); $newPlanning->first_day = $monday; $newPlanning->last_day = $sunday; $newPlanning->save(); } $monday->addWeek(); $sunday->addWeek(); } }