/** * @param int $id * @param string $slug * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException * * @return View|RedirectResponse */ public function viewCategory(int $id, string $slug) { /** @var Category $category */ $category = $this->category->findOrFail(Category::privateId($id)); if ($category->slug() !== $slug) { return $this->webUi->redirect('categories.view', [$category->id, $category->slug()]); } $tree = $category->getDescendantsAndSelf()->load(['products' => function ($query) { /* @var Product $query */ $query->with(Product::standardRelations()); }]); return $this->webUi->view('customer.category.view', compact('category', 'tree')); }
/** * @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')); }
/** * @return Paginator */ public function loadInStock() : Paginator { return $this->productResource->inStock()->with(Product::standardRelations())->orderBy('updated_at', 'desc')->take(120)->paginate(); }