/** * post Store. * * @param Request $request Input data of booking form * * @return Response Redirect to Appointments listing */ public function postStore(Request $request) { $this->log->info(__METHOD__); ////////////////// // FOR REFACTOR // ////////////////// $issuer = auth()->user(); $business = Business::findOrFail($request->input('businessId')); $contact = $issuer->getContactSubscribedTo($business->id); $service = Service::find($request->input('service_id')); $strDateTime = $request->input('_date') . ' ' . $business->pref('start_at'); $datetime = Carbon::parse($strDateTime . ' ' . $business->timezone)->setTimezone('UTC'); $comments = $request->input('comments'); $this->concierge->setBusiness($business); $appointment = $this->concierge->makeReservation($issuer, $business, $contact, $service, $datetime, $comments); if (false === $appointment) { $this->log->info('[ADVICE] Unable to book'); Flash::warning(trans('user.booking.msg.store.error')); return redirect()->route('user.agenda'); } if (!$appointment->exists) { $this->log->info('[ADVICE] Appointment is duplicated'); Flash::warning(trans('user.booking.msg.store.sorry_duplicated', ['code' => $appointment->code])); return redirect()->route('user.agenda'); } $this->log->info('Appointment saved successfully'); event(new NewBooking($issuer, $appointment)); Flash::success(trans('user.booking.msg.store.success', ['code' => $appointment->code])); return redirect()->route('user.agenda'); }