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