42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Product;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class UpdateProductRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
// Based on existing controller logic, update rules are similar but allow optional fields if strictly updating parameters
|
|
// However, standard update often requires validating presence if they are being updated.
|
|
// Controller used specific rules.
|
|
|
|
// We need to fetch the product to know its type if 'type_id' is not in request (usually it is in hidden field).
|
|
// Assuming type_id is present in update form as per Controller logic.
|
|
|
|
$rules = [
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'price' => ['required', 'numeric', 'min:0'],
|
|
'product_id' => ['required', 'exists:products,id'],
|
|
];
|
|
|
|
$typeId = (int) $this->input('type_id');
|
|
|
|
if ($typeId === 4) { // VPS
|
|
$rules = array_merge($rules, [
|
|
'cpu' => ['required'],
|
|
'ram' => ['required'],
|
|
'disk' => ['required'],
|
|
]);
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
}
|