44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Product;
|
|
|
|
use App\Enums\Product\ProductTypeEnums;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class StoreProductRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'price' => ['required', 'numeric', 'min:0'],
|
|
'price_sale' => ['nullable', 'numeric', 'min:0'],
|
|
'description' => ['nullable', 'string'],
|
|
'status' => ['required', 'integer'], // Value from Status Enum
|
|
'type_id' => ['required', 'integer'],
|
|
];
|
|
|
|
// Infer product type from type_id (Legacy mapping needs to be consistent with Controller)
|
|
// Controller map: 1=>Addon, 2=>Domain, 3=>Hosting, 4=>VPS
|
|
// We can access input 'type_id'
|
|
$typeId = (int) $this->input('type_id');
|
|
|
|
if ($typeId === 4) { // VPS
|
|
$rules = array_merge($rules, [
|
|
'cpu' => ['required'],
|
|
'ram' => ['required'],
|
|
'disk' => ['required'],
|
|
'bandwidth' => ['required'],
|
|
]);
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
}
|