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

47 lines
1.6 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'],
'thumbnail' => ['nullable', 'image', 'max:5120'],
'images' => ['nullable', 'array'],
'images.*' => ['image', 'max:5120'],
'delete_image_ids' => ['nullable', 'array'],
'delete_image_ids.*' => ['integer'],
'stock' => [Rule::requiredIf($this->isMethod('post')), 'integer', 'min:0'],
];
}
}