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