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