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