feat: implement polymorphic relationships for group items to support bundles and product variants

This commit is contained in:
2026-07-17 14:42:44 -03:00
parent 615eacea91
commit cb0fb2899c
10 changed files with 298 additions and 19 deletions

View File

@@ -2,7 +2,10 @@
namespace App\Domains\Catalog\Requests;
use App\Domains\Bundle\Models\Bundle;
use App\Domains\Catalog\Models\ProductVariant;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class StoreFeaturedVariantRequest extends FormRequest
{
@@ -14,8 +17,25 @@ class StoreFeaturedVariantRequest extends FormRequest
public function rules(): array
{
return [
'product_variant_id' => ['required', 'integer'],
'groupable_type' => ['required', 'string', Rule::in(['variant', 'bundle'])],
'groupable_id' => [
'required',
'integer',
Rule::exists(match ($this->input('groupable_type')) {
'bundle' => 'bundles',
default => 'productos_variantes',
}, 'id'),
],
'order' => ['nullable', 'integer'],
];
}
public function mappedGroupableType(): string
{
return match ($this->input('groupable_type')) {
'variant' => ProductVariant::class,
'bundle' => Bundle::class,
default => throw new \InvalidArgumentException('Invalid groupable type'),
};
}
}