38 lines
952 B
PHP
38 lines
952 B
PHP
<?php
|
|
|
|
namespace App\Domains\Cart\Requests;
|
|
|
|
use App\Domains\Bundle\Models\Bundle;
|
|
use App\Domains\Catalog\Models\ProductVariant;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class AddCartItemRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'buyable_type' => ['required', 'string', Rule::in(['variant', 'bundle'])],
|
|
'buyable_id' => ['required', 'integer'],
|
|
'cantidad' => ['required', 'integer', 'min:1'],
|
|
];
|
|
}
|
|
|
|
public function mappedBuyableType(): string
|
|
{
|
|
return match ($this->input('buyable_type')) {
|
|
'variant' => ProductVariant::class,
|
|
'bundle' => Bundle::class,
|
|
default => throw new \InvalidArgumentException('Invalid buyable type'),
|
|
};
|
|
}
|
|
}
|