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