dress/app/Http/Requests/Admin/Manage/Order/AddToCartRequest.php

45 lines
1.1 KiB
PHP

<?php
namespace App\Http\Requests\Admin\Manage\Order;
use App\Enums\PriceType;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class AddToCartRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'product_id' => [
Rule::requiredIf($this->isMethod('post')),
Rule::exists('products', 'id'),
],
'qty' => ['required', 'integer'],
'price' => [
Rule::requiredIf($this->isMethod('post')),
'integer',
'min:0',
],
'price_type' => [
Rule::requiredIf($this->isMethod('post')),
Rule::enum(PriceType::class),
],
];
}
}