repository = $dependents; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Bixo\Employee\Repositories\Criteria\DependentsResourceCriteria::class); } /** * Display a list of dependents. * * @return Response */ public function index(DependentsRequest $request) { return $this->repository ->setPresenter(\Bixo\Employee\Repositories\Presenter\DependentsPresenter::class) ->paginate(); } /** * Display dependents. * * @param Request $request * @param Model $dependents * * @return Response */ public function show(DependentsRequest $request, Dependents $dependents) { return $dependents->setPresenter(\Bixo\Employee\Repositories\Presenter\DependentsListPresenter::class); ; } /** * Create new dependents. * * @param Request $request * * @return Response */ public function store(DependentsRequest $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::dependents.name')]); $code = 204; $status = 'success'; $url = guard_url('employee/dependents/' . $dependents->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('employee/dependents'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the dependents. * * @param Request $request * @param Model $dependents * * @return Response */ public function update(DependentsRequest $request, Dependents $dependents) { try { $data = $request->all(); $dependents->update($data); $message = trans('messages.success.updated', ['Module' => trans('employee::dependents.name')]); $code = 204; $status = 'success'; $url = guard_url('employee/dependents/' . $dependents->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('employee/dependents/' . $dependents->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the dependents. * * @param Model $dependents * * @return Response */ public function destroy(DependentsRequest $request, Dependents $dependents) { try { $dependents->delete(); $message = trans('messages.success.deleted', ['Module' => trans('employee::dependents.name')]); $code = 202; $status = 'success'; $url = guard_url('employee/dependents/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('employee/dependents/' . $dependents->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); } }