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