ldc-legaulois/app/Http/Requests/Bo/SellItems/StoreSellItemRequest.php
2026-09-25 16:25:31 +02:00

69 lines
2.1 KiB
PHP

<?php
namespace App\Http\Requests\Bo\SellItems;
use App\Enums\Shop\SellItemsType;
use App\Models\SellItem;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
use Illuminate\Validation\Rules\Enum;
class StoreSellItemRequest extends FormRequest
{
use HasPicture;
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return Gate::check('create', SellItem::class);
}
/**
* Prepare the data for validation.
*/
protected function prepareForValidation(): void
{
$this->mergePicture('picture');
}
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
$rules = [
'name' => 'required|string|between:3,255',
'type' => ['required', new Enum(SellItemsType::class)],
'price' => 'required|numeric|between:0.1,100',
'picture_alt' => 'required|string|between:3,255',
'picture_title' => 'required|string|between:3,255',
'arcadia_id' => 'required|integer|between:0,1000',
'arcadia_weight' => 'required|integer|between:0,100',
];
return \array_merge(
$rules,
$this->pictureRules('picture', 450, 450, 450, 450),
);
}
/**
* Get custom attributes for validator errors.
*/
public function attributes(): array
{
return [
'name' => trans('validation.attributes.name'),
'type' => trans('validation.custom.type'),
'price' => trans('validation.attributes.price'),
'picture' => trans('validation.attributes.image'),
'picture_alt' => trans('validation.custom.attribute_alt'),
'picture_title' => trans('validation.custom.attribute_title'),
'arcadia_id' => trans('validation.custom.arcadia_id'),
'arcadia_weight' => trans('validation.custom.arcadia_weight'),
];
}
}