feat: product pricing plans

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Doar Mihai
2026-10-17 16:02:27 +03:00
co-authored by Claude Sonnet 5.5
parent a3894d2f37
commit 768c814762
10 changed files with 229 additions and 1 deletions
@@ -3,12 +3,14 @@
namespace App\Http\Controllers;
use App\Models\Category;
use App\Models\PricingPlan;
use App\Models\Product;
use App\Models\Tag;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Storage;
use Illuminate\Validation\Rule;
use Laravel\Pennant\Feature;
class ProductController extends Controller
@@ -227,6 +229,11 @@ class ProductController extends Controller
'screenshots.*' => 'image|mimes:jpeg,png,jpg,gif|max:2048',
'remove_screenshots' => 'nullable|array',
'remove_screenshots.*' => 'integer',
'plans' => 'nullable|array',
'plans.*.name' => 'required|string|max:100',
'plans.*.price' => 'required|numeric|min:0|max:99999',
'plans.*.period' => ['required', Rule::in(PricingPlan::PERIODS)],
'plans.*.description' => 'nullable|string|max:255',
];
}
@@ -235,6 +242,18 @@ class ProductController extends Controller
*/
protected function syncDetails(Request $request, Product $product): void
{
// The submitted plan list replaces all existing plans
$product->pricingPlans()->delete();
foreach (array_values((array) $request->input('plans', [])) as $i => $plan) {
$product->pricingPlans()->create([
'name' => $plan['name'],
'price' => $plan['price'],
'period' => $plan['period'],
'description' => $plan['description'] ?? null,
'position' => $i,
]);
}
// Only rows belonging to this product may be removed
$ids = array_filter((array) $request->input('remove_screenshots', []));
if ($ids) {