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