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