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