public function storeCompanyReminderSchedule(Request $request) { $company = Auth::user()->get()->company; $companyReminderSchedule = CompanyReminderSchedule::where('company_id', $company->id)->first(); if (!$companyReminderSchedule) { $companyReminderSchedule = new CompanyReminderSchedule(); } $companyReminderSchedule->monday = $request->input('monday'); $companyReminderSchedule->tuesday = $request->input('tuesday'); $companyReminderSchedule->wednesday = $request->input('wednesday'); $companyReminderSchedule->thursday = $request->input('thursday'); $companyReminderSchedule->friday = $request->input('friday'); $companyReminderSchedule->saturday = $request->input('saturday'); $companyReminderSchedule->sunday = $request->input('sunday'); $companyReminderSchedule->save(); $company->reminderSchedule()->save($companyReminderSchedule); return $this->success($companyReminderSchedule); }
/** * Execute the console command. * * @return mixed */ public function handle() { $days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday']; $schudules = CompanyReminderSchedule::with('company.users')->where($days[Carbon::now()->dayOfWeek], true)->get(); foreach ($schudules as $schudule) { foreach ($schudule->company->users as $user) { $orders = $this->navisionService->getUserUnconfirmedOrders($user->company->nav_code); Mail::send('user::emails.reminder', ['user' => $user, 'count' => count($orders)], function ($mail) use($user) { $mail->to($user->username)->subject('You have unconfirmed orders'); }); } } }