/** * @param Request $request * @param int $id * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException * * @return \Illuminate\Http\RedirectResponse */ public function putProducts(Request $request, int $id) { /** @var Offer $offer */ $offer = $this->offer->findOrFail($id); $offer->products()->sync((array) $request->get('product-ids')); $this->webUi->successMessage("Set products for offer `{$offer->name}`."); return $this->webUi->redirect('offers.index'); }
/** * @param int $offerId * @param string $slug * * @throws ModelNotFoundException * * @return View|RedirectResponse */ public function view(int $offerId, string $slug) { /** @var Offer $offer */ $offer = Offer::findOrFail($offerId); if ($offer->slug() !== $slug) { return $this->webUi->redirect('offer.show', [$offerId, $offer->slug()]); } $products = Product::whereHas('offers', function ($query) use($offer) { /* @var Builder $query */ $query->where('id', '=', $offer->id); })->with(Product::standardRelations())->paginate(); return $this->webUi->view('sales::offer.view', compact('offer', 'products')); }