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) { return $this->repository ->setPresenter(\Bixo\Employee\Repositories\Presenter\BenefitsPresenter::class) ->paginate(); } /** * Display benefits. * * @param Request $request * @param Model $benefits * * @return Response */ public function show(BenefitsRequest $request, Benefits $benefits) { return $benefits->setPresenter(\Bixo\Employee\Repositories\Presenter\BenefitsListPresenter::class); ; } /** * Create new benefits. * * @param Request $request * * @return Response */ public function store(BenefitsRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('employee::benefits.name')]); $code = 204; $status = 'success'; $url = guard_url('employee/benefits/' . $benefits->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('employee/benefits'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the benefits. * * @param Request $request * @param Model $benefits * * @return Response */ public function update(BenefitsRequest $request, Benefits $benefits) { try { $data = $request->all(); $benefits->update($data); $message = trans('messages.success.updated', ['Module' => trans('employee::benefits.name')]); $code = 204; $status = 'success'; $url = guard_url('employee/benefits/' . $benefits->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('employee/benefits/' . $benefits->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the benefits. * * @param Model $benefits * * @return Response */ public function destroy(BenefitsRequest $request, Benefits $benefits) { try { $benefits->delete(); $message = trans('messages.success.deleted', ['Module' => trans('employee::benefits.name')]); $code = 202; $status = 'success'; $url = guard_url('employee/benefits/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('employee/benefits/' . $benefits->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }