| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
-
- namespace App\Http\Controllers;
-
- use App\StorePlan\PlanSchema;
- use App\StorePlan\PlanValidator;
- use App\StorePlan\SectionLayouts;
- use Illuminate\Http\RedirectResponse;
- use Illuminate\Http\Request;
- use Illuminate\Validation\Rule;
- use Inertia\Inertia;
-
- /**
- * Changes one section's layout from the Design tab's Layouts box.
- * This changes the working design, so a live store shows it after "Publish changes".
- */
- class SectionLayoutController extends Controller
- {
- public function update(Request $request, PlanValidator $validator, string $slug, string $sectionId): RedirectResponse
- {
- $store = $request->user()->stores()->where('slug', $slug)->firstOrFail();
-
- abort_if($store->plan === null, 404);
-
- $type = SectionLayouts::typeOf($store->plan, $sectionId);
-
- abort_if($type === null, 404);
-
- $validated = $request->validate([
- 'variant' => ['required', Rule::in(PlanSchema::SECTIONS[$type])],
- ]);
-
- $store->plan = $validator->validate(SectionLayouts::update($store->plan, $sectionId, $validated['variant']));
- $store->save();
-
- Inertia::flash('toast', ['type' => 'success', 'message' => $store->isPublished()
- ? __('Saved. Click "Publish changes" to show it on your live store.')
- : __('Layout saved.')]);
-
- return to_route('stores.show', $store->slug);
- }
- }
|