render($this->ownedStore($request, $slug), ['type' => 'page', 'pageId' => PlanSchema::HOME_PAGE]); } /** * The shop page: every product shoppers may see. */ public function shop(Request $request, string $slug): Response { return $this->render($this->ownedStore($request, $slug), ['type' => 'shop']); } /** * One product's own page. */ public function product(Request $request, string $slug, string $productSlug): Response { $store = $this->ownedStore($request, $slug); $product = $store->products()->active()->with('images')->where('slug', $productSlug)->firstOrFail(); return $this->render($store, ['type' => 'product', 'product' => $product->toStorefront()]); } /** * Every storefront page gets the same basics: the plan, the fonts and the product list. * * @param array $view Which page to show. */ private function render(Store $store, array $view): Response { abort_if($store->plan === null, 404); return Inertia::render('stores/preview', [ 'storeName' => $store->name, 'language' => $store->language->value, 'plan' => $store->plan, 'fonts' => PlanSchema::FONTS, // Links inside the storefront are built on top of this address. 'baseUrl' => route('stores.preview', $store->slug, false), 'view' => $view, 'products' => $store->products() ->active() ->with('images') ->latest('id') ->limit(60) ->get() ->map(fn (Product $product) => $product->toStorefront()), ]); } private function ownedStore(Request $request, string $slug): Store { return $request->user()->stores()->where('slug', $slug)->firstOrFail(); } }