/** * @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 $id * @param Request $request * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException * * @return \Illuminate\Http\RedirectResponse */ public function putCategoryParent(int $id, Request $request) { /** @var Category $category */ $category = $this->category->findOrFail($id); if ((int) $request->get('parent-id') === -1) { $category->makeRoot(); $this->webUi->successMessage("Made `{$category->name}` a root-level category."); return $this->webUi->redirect('categories.index'); } /** @var Category $parent */ $parent = $this->category->findOrFail($request->get('parent-id')); $category->makeChildOf($parent); $this->webUi->successMessage("Made `{$category->name}` a child of `{$parent->name}`."); return $this->webUi->redirect('categories.index'); }