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