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