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