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