AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

StoreController.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Enums\StoreCategory;
  4. use App\Enums\StoreLanguage;
  5. use App\Http\Requests\Stores\CreateStoreRequest;
  6. use App\Models\Store;
  7. use Illuminate\Http\RedirectResponse;
  8. use Illuminate\Http\Request;
  9. use Inertia\Inertia;
  10. use Inertia\Response;
  11. class StoreController extends Controller
  12. {
  13. /**
  14. * Show the dashboard with the user's own stores.
  15. */
  16. public function index(Request $request): Response
  17. {
  18. return Inertia::render('dashboard', [
  19. 'stores' => $request->user()
  20. ->stores()
  21. ->latest()
  22. ->get()
  23. ->map(fn (Store $store) => $this->present($store)),
  24. ]);
  25. }
  26. /**
  27. * Show the "create a store" form.
  28. */
  29. public function create(): Response
  30. {
  31. return Inertia::render('stores/create', [
  32. 'categories' => StoreCategory::options(),
  33. 'languages' => StoreLanguage::options(),
  34. ]);
  35. }
  36. /**
  37. * Save a new store for the current user.
  38. */
  39. public function store(CreateStoreRequest $request): RedirectResponse
  40. {
  41. $store = $request->user()->stores()->create($request->validated());
  42. Inertia::flash('toast', ['type' => 'success', 'message' => __('Store created.')]);
  43. return to_route('stores.show', $store->slug);
  44. }
  45. /**
  46. * Show one store. Looking it up through the user means other people's stores give a 404.
  47. */
  48. public function show(Request $request, string $slug): Response
  49. {
  50. $store = $request->user()->stores()->where('slug', $slug)->firstOrFail();
  51. return Inertia::render('stores/show', [
  52. 'store' => $this->present($store),
  53. ]);
  54. }
  55. /**
  56. * The store fields the frontend is allowed to see.
  57. *
  58. * @return array<string, mixed>
  59. */
  60. private function present(Store $store): array
  61. {
  62. return [
  63. 'id' => $store->id,
  64. 'name' => $store->name,
  65. 'slug' => $store->slug,
  66. 'category' => $store->category->value,
  67. 'category_label' => $store->category->label(),
  68. 'description' => $store->description,
  69. 'language' => $store->language->value,
  70. 'language_label' => $store->language->label(),
  71. 'status' => $store->status->value,
  72. 'status_label' => $store->status->label(),
  73. 'has_design' => $store->plan !== null,
  74. 'created_at' => $store->created_at?->toIso8601String(),
  75. ];
  76. }
  77. }