Bonus::orderBy('order')->get() ]); } public function create() { return Inertia::render('Admin/Bonuses/Create', [ 'predefinedBadges' => Config::get('bonuses.predefined_badges', []), 'predefinedKeyFeatures' => Config::get('bonuses.predefined_key_features', []), ]); } public function store(Request $request) { $validated = $request->validate([ 'name' => 'required|string|max:255', 'description' => 'nullable|string', 'image_path' => 'nullable|string', 'image_file' => 'nullable|image|max:2048', // 2MB Max 'brand_color' => 'nullable|string', 'hover_color' => 'nullable|string', 'badges' => 'nullable|array', 'badges.*.label' => 'required_with:badges|string|max:255', 'badges.*.class' => 'nullable|string|max:255', 'min_deposit' => 'nullable|string', 'max_bet' => 'nullable|string', 'wagering' => 'nullable|string', 'free_spins' => 'nullable|string', 'button_link' => 'nullable|string', 'key_features' => 'nullable|array', 'key_features.*' => 'required_with:key_features|string|max:255', 'is_sticky' => 'boolean', 'is_no_deposit' => 'boolean', 'is_featured' => 'boolean', 'order' => 'integer', ]); if ($request->hasFile('image_file')) { $path = $request->file('image_file')->store('bonuses', 'public'); $validated['image_path'] = Storage::url($path); } Bonus::create($validated); return redirect()->route('admin.bonuses.index')->with('success', 'Bonus created successfully.'); } public function edit(Bonus $bonus) { return Inertia::render('Admin/Bonuses/Edit', [ 'bonus' => $bonus, 'predefinedBadges' => Config::get('bonuses.predefined_badges', []), 'predefinedKeyFeatures' => Config::get('bonuses.predefined_key_features', []), ]); } public function update(Request $request, Bonus $bonus) { $validated = $request->validate([ 'name' => 'required|string|max:255', 'description' => 'nullable|string', 'image_path' => 'nullable|string', 'image_file' => 'nullable|image|max:2048', 'brand_color' => 'nullable|string', 'hover_color' => 'nullable|string', 'badges' => 'nullable|array', 'badges.*.label' => 'required_with:badges|string|max:255', 'badges.*.class' => 'nullable|string|max:255', 'min_deposit' => 'nullable|string', 'max_bet' => 'nullable|string', 'wagering' => 'nullable|string', 'free_spins' => 'nullable|string', 'button_link' => 'nullable|string', 'key_features' => 'nullable|array', 'key_features.*' => 'required_with:key_features|string|max:255', 'is_sticky' => 'boolean', 'is_no_deposit' => 'boolean', 'is_featured' => 'boolean', 'order' => 'integer', ]); if ($request->hasFile('image_file')) { // Delete old file if exists and it was an uploaded one if ($bonus->image_path && str_contains($bonus->image_path, '/storage/bonuses/')) { $oldPath = str_replace('/storage/', '', $bonus->image_path); Storage::disk('public')->delete($oldPath); } $path = $request->file('image_file')->store('bonuses', 'public'); $validated['image_path'] = Storage::url($path); } $bonus->update($validated); return redirect()->route('admin.bonuses.index')->with('success', 'Bonus updated successfully.'); } public function destroy(Bonus $bonus) { if ($bonus->image_path && str_contains($bonus->image_path, '/storage/bonuses/')) { $oldPath = str_replace('/storage/', '', $bonus->image_path); Storage::disk('public')->delete($oldPath); } $bonus->delete(); return redirect()->route('admin.bonuses.index')->with('success', 'Bonus deleted successfully.'); } }