feat: product pricing plans
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
a3894d2f37
commit
768c814762
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user