form = JobForm::setAttributes()->toArray(); $this->modules = $this->modules(config('beejees.job.modules'), 'job', guard_url('job')); $this->repository = $job; } /** * Display a list of job. * * @return Response */ public function index(JobRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $data = $this->repository ->pushFilter(RequestFilter::class) ->pushFilter(JobResourceFilter::class) ->setPresenter(JobListPresenter::class) ->simplePaginate($pageLimit) // ->withQueryString() ->toArray(); extract($data); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('job::job.names')) ->view('job::job.index') ->data(compact('data', 'meta', 'links', 'modules', 'form')) ->output(); } /** * Display job. * * @param Request $request * @param Model $job * * @return Response */ public function show(JobRequest $request, JobRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('job::job.name')) ->data(compact('data', 'form', 'modules', 'form')) ->view('job::job.show') ->output(); } /** * Show the form for creating a new job. * * @param Request $request *x * @return Response */ public function create(JobRequest $request, JobRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('job::job.name')) ->view('job::job.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new job. * * @param Request $request * * @return Response */ public function store(JobRequest $request, JobRepositoryInterface $repository) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $repository->create($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.created', ['Module' => trans('job::job.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('job/job/' . $data['id'])) ->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, JobRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('job::job.name')) ->view('job::job.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the job. * * @param Request $request * @param Model $job * * @return Response */ public function update(JobRequest $request, JobRepositoryInterface $repository) { try { $attributes = $request->all(); $repository->update($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.updated', ['Module' => trans('job::job.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('job/job/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('job/job/' . $repository->getRouteKey())) ->redirect(); } } /** * Remove the job. * * @param Model $job * * @return Response */ public function destroy(JobRequest $request, JobRepositoryInterface $repository) { try { $repository->delete(); $data = $repository->toArray(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('job::job.name')])) ->code(202) ->status('success') ->data(compact('data')) ->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/' . $repository->getRouteKey())) ->redirect(); } } }