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