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