dress/app/Http/Requests/Admin/Master/ProductRequest.php

41 lines
1.2 KiB
PHP

<?php
namespace App\Http\Requests\Admin\Master;
use App\Models\Category;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class ProductRequest 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 [
'name' => ['required', 'string', 'max:100'],
'description' => ['nullable', 'string'],
'category_ids' => ['required', 'array'],
'category_ids.*' => Rule::exists(Category::class, 'id')->where('is_active', true),
'prices' => ['required', 'array'],
'prices.purchase' => ['required', 'integer', 'min:0'],
'prices.distributor' => ['required', 'integer', 'min:0'],
'prices.agent' => ['required', 'integer', 'min:0'],
'prices.reseller' => ['required', 'integer', 'min:0'],
'prices.retail' => ['required', 'integer', 'min:0'],
];
}
}