public function store(ProductCreationRequest $request) { if ($this->max and $this->account()->products()->count() >= $this->max) { throw new InvalidDataException('最多添加' . $this->max . '个商品'); } $product = $this->productManager->createProduct($this->account(), $request->all()); $this->flashSuccess('add'); return $this->redirectRoute('products.edit', $product->id); }
public function update(Request $request, ShippingPlan $shippingPlan) { if ($products = $request->input('products') ?: []) { // instead of authorizing each product against seller // simply filter out invalid and unauthorized products // only sync the valid product ids $products = $this->productManager->getProductRepository()->whereIn('id', $products)->whereSeller($this->account())->findAll(); } $shippingPlan->products()->sync($products); return $this->success('update'); }
public function index() { $products = $this->productManager->getProductRepository()->scopes('active')->with('image', 'variants')->paginate(); return view('product::__front.products.index', compact('products')); }