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