| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
-
- namespace App\Http\Controllers;
-
- use App\Models\Store;
- use App\StorePlan\PlanSchema;
- use App\StorePlan\PlanValidator;
- use App\StorePlan\SamplePlan;
- use Illuminate\Http\RedirectResponse;
- use Illuminate\Http\Request;
- use Inertia\Inertia;
- use Inertia\Response;
-
- class StoreDesignController extends Controller
- {
- /**
- * Show the storefront as a full page, drawn from the store's saved plan.
- */
- public function preview(Request $request, string $slug): Response
- {
- $store = $this->ownedStore($request, $slug);
-
- abort_if($store->plan === null, 404);
-
- return Inertia::render('stores/preview', [
- 'storeName' => $store->name,
- 'language' => $store->language->value,
- 'plan' => $store->plan,
- 'fonts' => PlanSchema::FONTS,
- ]);
- }
-
- /**
- * Give the store the hand-written sample design.
- * Temporary: this is replaced by AI generation in Step 3.
- */
- public function applySample(Request $request, PlanValidator $validator, string $slug): RedirectResponse
- {
- $store = $this->ownedStore($request, $slug);
-
- $store->plan = $validator->validate(SamplePlan::for($store));
- $store->save();
-
- Inertia::flash('toast', ['type' => 'success', 'message' => __('Sample design applied.')]);
-
- return to_route('stores.show', $store->slug);
- }
-
- private function ownedStore(Request $request, string $slug): Store
- {
- return $request->user()->stores()->where('slug', $slug)->firstOrFail();
- }
- }
|