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