form = CandidateForm::setAttributes()->toArray(); $this->modules = $this->modules(config('beejees.candidate.modules'), 'candidate', guard_url('candidate')); $this->repository = $candidate; } /** * Display a list of candidate. * * @return Response */ public function index(CandidateRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $data = $this->repository ->pushFilter(RequestFilter::class) ->pushFilter(CandidateResourceFilter::class) ->setPresenter(CandidateListPresenter::class) ->simplePaginate($pageLimit) // ->withQueryString() ->toArray(); extract($data); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('candidate::candidate.names')) ->view('candidate::candidate.index') ->data(compact('data', 'meta', 'links', 'modules', 'form')) ->output(); } /** * Display candidate. * * @param Request $request * @param Model $candidate * * @return Response */ public function show(CandidateRequest $request, CandidateRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('candidate::candidate.name')) ->data(compact('data', 'form', 'modules', 'form')) ->view('candidate::candidate.show') ->output(); } /** * Show the form for creating a new candidate. * * @param Request $request *x * @return Response */ public function create(CandidateRequest $request, CandidateRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('candidate::candidate.name')) ->view('candidate::candidate.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new candidate. * * @param Request $request * * @return Response */ public function store(CandidateRequest $request, CandidateRepositoryInterface $repository) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $repository->create($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.created', ['Module' => trans('candidate::candidate.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('candidate/candidate/' . $data['id'])) ->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, CandidateRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('candidate::candidate.name')) ->view('candidate::candidate.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the candidate. * * @param Request $request * @param Model $candidate * * @return Response */ public function update(CandidateRequest $request, CandidateRepositoryInterface $repository) { try { $attributes = $request->all(); $repository->update($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.updated', ['Module' => trans('candidate::candidate.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('candidate/candidate/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('candidate/candidate/' . $repository->getRouteKey())) ->redirect(); } } /** * Remove the candidate. * * @param Model $candidate * * @return Response */ public function destroy(CandidateRequest $request, CandidateRepositoryInterface $repository) { try { $repository->delete(); $data = $repository->toArray(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('candidate::candidate.name')])) ->code(202) ->status('success') ->data(compact('data')) ->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/' . $repository->getRouteKey())) ->redirect(); } } }