renderStorefront($request, $this->storefront($request), [ 'type' => 'page', 'pageId' => PlanSchema::HOME_PAGE, ]); } /** * Any other page of the design, such as "about". Its id is its address. */ public function page(Request $request): Response|RedirectResponse { $storefront = $this->storefront($request); $pageId = (string) $request->route('pageId'); if ($pageId === PlanSchema::HOME_PAGE) { return redirect($storefront->path()); } abort_unless(in_array($pageId, array_column($storefront->plan['pages'] ?? [], 'id'), true), 404); return $this->renderStorefront($request, $storefront, ['type' => 'page', 'pageId' => $pageId]); } /** * One collection's page: its name, description and active products. */ public function collection(Request $request): Response { $storefront = $this->storefront($request); $collection = $storefront->store->collections() ->with(['products' => fn ($query) => $query->active()->with(Product::STOREFRONT_RELATIONS)]) ->where('slug', (string) $request->route('collectionSlug')) ->firstOrFail(); return $this->renderStorefront($request, $storefront, [ 'type' => 'collection', 'collection' => $collection->toStorefront(), 'collectionProducts' => $collection->products->map(fn (Product $product) => $product->toStorefront())->values()->all(), ]); } /** * The shop page: every product shoppers may see. */ public function shop(Request $request): Response { return $this->renderStorefront($request, $this->storefront($request), ['type' => 'shop']); } /** * One product's own page. */ public function product(Request $request): Response { $storefront = $this->storefront($request); $product = $storefront->store->products() ->active() ->with(Product::STOREFRONT_RELATIONS) ->where('slug', (string) $request->route('productSlug')) ->firstOrFail(); return $this->renderStorefront($request, $storefront, [ 'type' => 'product', 'product' => $product->toStorefront(), 'related' => RelatedProducts::for($product)->map(fn (Product $item) => $item->toStorefront())->values()->all(), ]); } }