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