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