user()->stores()->where('slug', $slug)->firstOrFail(); abort_if($store->plan === null, 404); return $store; } /** * 404 unless the design has a section with this id and type. */ private function assertSection(Store $store, string $sectionId, string $type): void { abort_unless(SectionEditor::typeOf($store->plan ?? [], $sectionId) === $type, 404); } /** * Check the changed design with the plan checker and save it. A problem is shown under the box, * in the checker's own words, and nothing is saved. * * @param array $plan */ private function saveDesign(Store $store, PlanValidator $validator, array $plan, string $savedMessage): RedirectResponse { try { $store->plan = $validator->validate($plan); } catch (ValidationException $e) { throw ValidationException::withMessages(['section' => collect($e->errors())->flatten()->first() ?? __('This change could not be saved.')]); } $store->save(); Inertia::flash('toast', ['type' => 'success', 'message' => $store->isPublished() ? __('Saved. Click "Publish changes" to show it on your live store.') : $savedMessage]); return to_route('stores.show', $store->slug); } }