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