repository = $appointment; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Hospital\Appointment\Repositories\Criteria\AppointmentResourceCriteria::class); } /** * Display a list of appointment. * * @return Response */ public function index(AppointmentRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Hospital\Appointment\Repositories\Presenter\AppointmentPresenter::class) ->$function(); } $appointments = $this->repository->paginate(); return $this->response->title(trans('appointment::appointment.names')) ->view('appointment::appointment.index', true) ->data(compact('appointments')) ->output(); } /** * Display appointment. * * @param Request $request * @param Model $appointment * * @return Response */ public function show(AppointmentRequest $request, Appointment $appointment) { if ($appointment->exists) { $view = 'appointment::appointment.show'; } else { $view = 'appointment::appointment.new'; } return $this->response->title(trans('app.view') . ' ' . trans('appointment::appointment.name')) ->data(compact('appointment')) ->view($view, true) ->output(); } /** * Show the form for creating a new appointment. * * @param Request $request * * @return Response */ public function create(AppointmentRequest $request) { $appointment = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('appointment::appointment.name')) ->view('appointment::appointment.create', true) ->data(compact('appointment')) ->output(); } /** * Create new appointment. * * @param Request $request * * @return Response */ public function store(AppointmentRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $appointment = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('appointment::appointment.name')])) ->code(204) ->status('success') ->url(guard_url('appointment/appointment/' . $appointment->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/appointment/appointment')) ->redirect(); } } /** * Show appointment for editing. * * @param Request $request * @param Model $appointment * * @return Response */ public function edit(AppointmentRequest $request, Appointment $appointment) { return $this->response->title(trans('app.edit') . ' ' . trans('appointment::appointment.name')) ->view('appointment::appointment.edit', true) ->data(compact('appointment')) ->output(); } /** * Update the appointment. * * @param Request $request * @param Model $appointment * * @return Response */ public function update(AppointmentRequest $request, Appointment $appointment) { try { $attributes = $request->all(); $appointment->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('appointment::appointment.name')])) ->code(204) ->status('success') ->url(guard_url('appointment/appointment/' . $appointment->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('appointment/appointment/' . $appointment->getRouteKey())) ->redirect(); } } /** * Remove the appointment. * * @param Model $appointment * * @return Response */ public function destroy(AppointmentRequest $request, Appointment $appointment) { try { $appointment->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('appointment::appointment.name')])) ->code(202) ->status('success') ->url(guard_url('appointment/appointment/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('appointment/appointment/' . $appointment->getRouteKey())) ->redirect(); } } /** * Remove multiple appointment. * * @param Model $appointment * * @return Response */ public function delete(AppointmentRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('appointment::appointment.name')])) ->status("success") ->code(202) ->url(guard_url('appointment/appointment')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/appointment/appointment')) ->redirect(); } } /** * Restore deleted appointments. * * @param Model $appointment * * @return Response */ public function restore(AppointmentRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('appointment::appointment.name')])) ->status("success") ->code(202) ->url(guard_url('/appointment/appointment')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/appointment/appointment/')) ->redirect(); } } }