user()->stores()->where('slug', $slug)->firstOrFail(); abort_if($store->plan === null, 404); abort_unless(in_array($sectionId, array_column(FeaturedProducts::sections($store->plan), 'section_id'), true), 404); $validated = $request->validate([ // Only this store's own products that shoppers can see. Empty means "no product". 'product_slug' => ['nullable', 'string', Rule::exists('products', 'slug') ->where('store_id', $store->id) ->where('status', 'active')], ], [ 'product_slug.exists' => __('Choose one of your active products.'), ]); $store->plan = $validator->validate( FeaturedProducts::link($store->plan, $sectionId, $validated['product_slug'] ?? null), ); $store->save(); Inertia::flash('toast', ['type' => 'success', 'message' => $store->isPublished() ? __('Saved. Click "Publish changes" to show it on your live store.') : __('Featured product saved.')]); return to_route('stores.show', $store->slug); } }