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