ownedStore($request, $slug); $request->validate([ 'logo' => [ 'required', 'image', 'mimes:jpg,jpeg,png,webp', 'max:2048', 'dimensions:min_width='.StoreLogos::MIN_SIDE.',min_height='.StoreLogos::MIN_SIDE.',max_width=6000,max_height=6000', ], ], [ 'logo.max' => __('The logo must be 2 MB or smaller.'), 'logo.mimes' => __('Use a PNG, JPG or WebP picture. PNG keeps a see-through background.'), 'logo.dimensions' => __('Use a picture at least :size pixels on each side.', ['size' => StoreLogos::MIN_SIDE]), ]); try { $logos->upload($store, $request->file('logo')); } catch (RuntimeException) { return back()->withErrors(['logo' => __('That picture could not be read. Try saving it as PNG.')]); } Inertia::flash('toast', ['type' => 'success', 'message' => __('Logo uploaded. It shows on your store now.')]); return back(); } /** * Use a ready design, or one of the logos Claude drew. */ public function choose(Request $request, string $slug, StoreLogos $logos): RedirectResponse { $store = $this->ownedStore($request, $slug); $validated = $request->validate([ 'design' => ['required_without:drawn', 'nullable', Rule::in(StoreLogos::DESIGNS)], 'drawn' => ['required_without:design', 'nullable', 'integer', 'min:0'], ]); if (filled($validated['design'] ?? null)) { $logos->useDesign($store, $validated['design']); } elseif (! $logos->useDrawn($store, (int) $validated['drawn'])) { return back()->withErrors(['logo' => __('That logo is no longer available.')]); } Inertia::flash('toast', ['type' => 'success', 'message' => __('Logo saved. It shows on your store now.')]); return back(); } /** * Ask Claude for new logos. Each store has a lifetime number of tries. */ public function draw(Request $request, string $slug, StoreLogos $logos): RedirectResponse { $store = $this->ownedStore($request, $slug); try { $made = $logos->draw($store); } catch (AiException $e) { report($e); return back()->withErrors(['logo' => __('The AI could not draw logos just now. This try was not counted. Please try again.')]); } if ($made === null) { return back()->withErrors(['logo' => __('You have used all :count AI logo tries for this store. You can still pick any logo drawn before, a ready design, or upload your own.', ['count' => $logos->tryLimit()])]); } Inertia::flash('toast', ['type' => 'success', 'message' => __('The AI drew :count new logos. Pick one below.', ['count' => $made])]); return back(); } public function destroy(Request $request, string $slug, StoreLogos $logos): RedirectResponse { $logos->remove($this->ownedStore($request, $slug)); Inertia::flash('toast', ['type' => 'success', 'message' => __('Logo removed. Your store shows its name instead.')]); return back(); } private function ownedStore(Request $request, string $slug): Store { return $request->user()->stores()->where('slug', $slug)->firstOrFail(); } }