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