108 lines
4.2 KiB
PHP
108 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Enums\EleveurOcbStatus;
|
|
use App\Enums\GeoType;
|
|
use App\Enums\OCBType;
|
|
use App\Enums\PresentationType;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class StoreOcbBreeder extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return auth()->check();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
'breeder_code' => 'required|string|min:2|max:50',
|
|
'first_name' => 'required|string|min:2|max:150',
|
|
'last_name' => 'required|string|min:2|max:150',
|
|
|
|
'picture' => 'required|image|mimes:jpeg,png,jpg|max:2048',
|
|
|
|
'postal_code' => 'required|string|min:5|max:20',
|
|
'place' => 'required|string|min:2|max:255',
|
|
'testimony' => 'required|string',
|
|
'latitude' => 'required|numeric|between:-99.99,99.99',
|
|
'longitude' => 'required|numeric|between:-99.99,99.99',
|
|
'geo_type' => [
|
|
'required',
|
|
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
function ($attribute, $value, $fail) {
|
|
if (!in_array($value, GeoType::toValues())) {
|
|
$fail(__('Veuillez choisir entre :values', [
|
|
'value' => implode(',', GeoType::toLabels())
|
|
]));
|
|
}
|
|
}
|
|
],
|
|
'ocbStatus' => [
|
|
'required',
|
|
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
function ($attribute, $value, $fail) {
|
|
if (!in_array($value, EleveurOcbStatus::toValues())) {
|
|
$fail(__('Veuillez choisir entre :values', [
|
|
'value' => implode(',', EleveurOcbStatus::toLabels())
|
|
]));
|
|
}
|
|
}
|
|
],
|
|
'ocbType' => [
|
|
'required',
|
|
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
function ($attribute, $value, $fail) {
|
|
if (!in_array($value, OCBType::toValues())) {
|
|
$fail(__('Veuillez choisir entre :values', [
|
|
'value' => implode(',', OCBType::toLabels())
|
|
]));
|
|
}
|
|
}
|
|
],
|
|
'presentation_type' => [
|
|
'required',
|
|
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
function ($attribute, $value, $fail) {
|
|
if (!in_array($value, PresentationType::toValues())) {
|
|
$fail(__('Veuillez choisir entre :values', [
|
|
'value' => implode(',', PresentationType::toLabels())
|
|
]));
|
|
}
|
|
}
|
|
],
|
|
'audit' => 'boolean',
|
|
'valid_marketing_date' => 'nullable|date',
|
|
'video_link' => 'string|max:255',
|
|
'picture1' => 'image|mimes:jpeg,png,jpg|max:2048',
|
|
'picture2' => 'image|mimes:jpeg,png,jpg|max:2048',
|
|
'picture3' => 'image|mimes:jpeg,png,jpg|max:2048',
|
|
'status' => 'boolean',
|
|
'display_random' => 'boolean',
|
|
'inuavs' => 'array',
|
|
'inuavs.*' => [
|
|
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
function ($attribute, $value, $fail) {
|
|
if (strpos(trim($value), ' ') !== false) {
|
|
$fail(trans('Les espaces ne sont pas autorisés dans les codes INUAV'));
|
|
}
|
|
if (count($this->inuavs) > count(array_unique($this->inuavs))) {
|
|
$fail(trans('Les codes INUAVS doinvent être uniques'));
|
|
}
|
|
}
|
|
],
|
|
];
|
|
}
|
|
}
|