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