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

40 lines
978 B
PHP

<?php
namespace App\Http\Requests\Admin\Manage\Purchase;
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'),
],
'quantity' => ['required', 'integer', 'min:1'],
'unit_price' => [
Rule::requiredIf($this->isMethod('post')),
'integer',
'min:0',
],
];
}
}