ldc-legaulois/app/Http/Requests/Bo/SellItems/StoreSellItemRequest.php

70 lines
2.1 KiB
PHP
Raw Permalink Normal View History

2024-09-24 16:48:16 +02:00
<?php
namespace App\Http\Requests\Bo\SellItems;
use App\Enums\Shop\SellItemsType;
2024-09-24 16:48:16 +02:00
use App\Models\SellItem;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
use Illuminate\Validation\Rules\Enum;
2024-09-24 16:48:16 +02:00
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)],
2024-09-24 16:48:16 +02:00
'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',
];
2026-09-25 16:25:31 +02:00
2024-09-24 16:48:16 +02:00
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'),
2024-09-24 16:48:16 +02:00
'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'),
];
}
}