| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
-
- namespace App\Http\Controllers;
-
- use App\Http\Controllers\Concerns\RendersStorefront;
- use App\StorePlan\PlanSchema;
- use Illuminate\Http\RedirectResponse;
- use Illuminate\Http\Request;
- use Inertia\Response;
-
- /**
- * The storefront pages: home, shop and product.
- */
- class StoreDesignController extends Controller
- {
- use RendersStorefront;
-
- /**
- * The home page of the storefront, drawn from the store's saved plan.
- */
- public function preview(Request $request, string $slug): Response
- {
- return $this->renderStorefront($request, $this->ownedStore($request, $slug), [
- 'type' => 'page',
- 'pageId' => PlanSchema::HOME_PAGE,
- ]);
- }
-
- /**
- * Any other page of the plan, such as "about". Its id is its address.
- */
- public function page(Request $request, string $slug, string $pageId): Response|RedirectResponse
- {
- $store = $this->ownedStore($request, $slug);
-
- if ($pageId === PlanSchema::HOME_PAGE) {
- return to_route('stores.preview', $store->slug);
- }
-
- abort_unless(in_array($pageId, array_column($store->plan['pages'] ?? [], 'id'), true), 404);
-
- return $this->renderStorefront($request, $store, ['type' => 'page', 'pageId' => $pageId]);
- }
-
- /**
- * The shop page: every product shoppers may see.
- */
- public function shop(Request $request, string $slug): Response
- {
- return $this->renderStorefront($request, $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->renderStorefront($request, $store, ['type' => 'product', 'product' => $product->toStorefront()]);
- }
- }
|