AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

StoreDesignController.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Product;
  4. use App\Models\Store;
  5. use App\StorePlan\PlanSchema;
  6. use Illuminate\Http\Request;
  7. use Inertia\Inertia;
  8. use Inertia\Response;
  9. class StoreDesignController extends Controller
  10. {
  11. /**
  12. * The home page of the storefront, drawn from the store's saved plan.
  13. */
  14. public function preview(Request $request, string $slug): Response
  15. {
  16. return $this->render($this->ownedStore($request, $slug), ['type' => 'page', 'pageId' => PlanSchema::HOME_PAGE]);
  17. }
  18. /**
  19. * The shop page: every product shoppers may see.
  20. */
  21. public function shop(Request $request, string $slug): Response
  22. {
  23. return $this->render($this->ownedStore($request, $slug), ['type' => 'shop']);
  24. }
  25. /**
  26. * One product's own page.
  27. */
  28. public function product(Request $request, string $slug, string $productSlug): Response
  29. {
  30. $store = $this->ownedStore($request, $slug);
  31. $product = $store->products()->active()->with('images')->where('slug', $productSlug)->firstOrFail();
  32. return $this->render($store, ['type' => 'product', 'product' => $product->toStorefront()]);
  33. }
  34. /**
  35. * Every storefront page gets the same basics: the plan, the fonts and the product list.
  36. *
  37. * @param array<string, mixed> $view Which page to show.
  38. */
  39. private function render(Store $store, array $view): Response
  40. {
  41. abort_if($store->plan === null, 404);
  42. return Inertia::render('stores/preview', [
  43. 'storeName' => $store->name,
  44. 'language' => $store->language->value,
  45. 'plan' => $store->plan,
  46. 'fonts' => PlanSchema::FONTS,
  47. // Links inside the storefront are built on top of this address.
  48. 'baseUrl' => route('stores.preview', $store->slug, false),
  49. 'view' => $view,
  50. 'products' => $store->products()
  51. ->active()
  52. ->with('images')
  53. ->latest('id')
  54. ->limit(60)
  55. ->get()
  56. ->map(fn (Product $product) => $product->toStorefront()),
  57. ]);
  58. }
  59. private function ownedStore(Request $request, string $slug): Store
  60. {
  61. return $request->user()->stores()->where('slug', $slug)->firstOrFail();
  62. }
  63. }