184 lines
9.5 KiB
PHP
184 lines
9.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Fo;
|
|
|
|
use App\Enums\Contact\CivilityEnum;
|
|
use App\Enums\Contact\ObjectEnum;
|
|
use App\Traits\Requests\HasPicture;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rules\Enum;
|
|
|
|
class ContactRequest extends FormRequest
|
|
{
|
|
use HasPicture;
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function prepareForValidation()
|
|
{
|
|
$this->merge([
|
|
'accept_rules' => $this->accept_rules ? true : false,
|
|
'send_data' => $this->send_data ? true : false,
|
|
]);
|
|
$this->mergePicture('file');
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
$rules = [
|
|
'civility' => ['sometimes', 'nullable', new Enum(CivilityEnum::class)],
|
|
'last_name' => 'sometimes|nullable|string|between:3,255',
|
|
'first_name' => 'sometimes|nullable|string|between:3,255',
|
|
'society' => 'sometimes|nullable|string|between:3,255',
|
|
'email' => 'required|email:rfc,strict,dns,spoof,filter|max:255',
|
|
'phone' => 'sometimes|nullable|numeric|min:0',
|
|
'address' => 'sometimes|nullable|string|between:3,255',
|
|
'postal_code' => 'sometimes|nullable|numeric|min:0',
|
|
'city' => 'sometimes|nullable|string|between:3,255',
|
|
'object' => ['sometimes', 'nullable', new Enum(ObjectEnum::class)],
|
|
'product_name' => [
|
|
'nullable', 'string', 'between:3,255',
|
|
// @phpcs:ignore Generic.Files.LineLength.TooLong
|
|
'required_with:product_date_limit,product_barcode,product_lot,product_date_consumption,product_location',
|
|
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
function ($attribute, $value, $fail) {
|
|
if ($this->get("object") != ObjectEnum::customerService->value()) {
|
|
$fail(\trans('le Champs :field doit être vide lorsque le champs objet
|
|
n\'est pas égale à :enumValue.', [
|
|
'field' => trans('validation.custom.product_name'),
|
|
'enumValue' => ObjectEnum::customerService->label(),
|
|
]));
|
|
}
|
|
}
|
|
],
|
|
'product_date_limit' => [
|
|
'sometimes', 'nullable', 'string', 'between:3,255',
|
|
// @phpcs:ignore Generic.Files.LineLength.TooLong
|
|
'required_with:product_name,product_barcode,product_lot,product_date_consumption,product_location',
|
|
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
function ($attribute, $value, $fail) {
|
|
if ($this->get("object") != ObjectEnum::customerService->value()) {
|
|
$fail(\trans('le Champs :field doit être vide lorsque le champs objet
|
|
n\'est pas égale à :enumValue.', [
|
|
'field' => trans('validation.custom.product_date_limit'),
|
|
'enumValue' => ObjectEnum::customerService->label(),
|
|
]));
|
|
}
|
|
}
|
|
],
|
|
'product_barcode' => [
|
|
'sometimes', 'nullable', 'numeric', 'min:0',
|
|
// @phpcs:ignore Generic.Files.LineLength.TooLong
|
|
'required_with:product_name,product_date_limit,product_lot,product_date_consumption,product_location',
|
|
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
function ($attribute, $value, $fail) {
|
|
if ($this->get("object") != ObjectEnum::customerService->value()) {
|
|
$fail(\trans('le Champs :field doit être vide lorsque le champs objet
|
|
n\'est pas égale à :enumValue.', [
|
|
'field' => trans('validation.custom.product_barcode'),
|
|
'enumValue' => ObjectEnum::customerService->label(),
|
|
]));
|
|
}
|
|
}
|
|
],
|
|
'product_lot' => [
|
|
'sometimes', 'nullable', 'numeric', 'min:0',
|
|
// @phpcs:ignore Generic.Files.LineLength.TooLong
|
|
'required_with:product_name,product_date_limit,product_barcode,product_date_consumption,product_location',
|
|
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
function ($attribute, $value, $fail) {
|
|
if ($this->get("object") != ObjectEnum::customerService->value()) {
|
|
$fail(\trans('le Champs :field doit être vide lorsque le champs objet
|
|
n\'est pas égale à :enumValue.', [
|
|
'field' => trans('validation.custom.product_lot'),
|
|
'enumValue' => ObjectEnum::customerService->label(),
|
|
]));
|
|
}
|
|
}
|
|
],
|
|
'product_date_consumption' => [
|
|
'sometimes', 'nullable', 'string', 'between:3,255',
|
|
// @phpcs:ignore Generic.Files.LineLength.TooLong
|
|
'required_with:product_name,product_date_limit,product_barcode,product_lot,product_location',
|
|
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
function ($attribute, $value, $fail) {
|
|
if ($this->get("object") != ObjectEnum::customerService->value()) {
|
|
$fail(\trans('le Champs :field doit être vide lorsque le champs objet
|
|
n\'est pas égale à :enumValue.', [
|
|
'field' => trans('validation.custom.product_date_consumption'),
|
|
'enumValue' => ObjectEnum::customerService->label(),
|
|
]));
|
|
}
|
|
}
|
|
],
|
|
'product_location' => [
|
|
'sometimes', 'nullable', 'string', 'between:3,255',
|
|
// @phpcs:ignore Generic.Files.LineLength.TooLong
|
|
'required_with:product_name,product_date_limit,product_barcode,product_lot,product_date_consumption',
|
|
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
function ($attribute, $value, $fail) {
|
|
if ($this->get("object") != ObjectEnum::customerService->value()) {
|
|
$fail(\trans('le Champs :field doit être vide lorsque le champs objet
|
|
n\'est pas égale à :enumValue.', [
|
|
'field' => trans('validation.custom.product_location'),
|
|
'enumValue' => ObjectEnum::customerService->label(),
|
|
]));
|
|
}
|
|
}
|
|
],
|
|
'message' => 'sometimes|nullable|string|between:3,255',
|
|
'accept_rules' => 'required|boolean',
|
|
'send_data' => 'required|boolean',
|
|
];
|
|
|
|
return \array_merge($rules, $this->pictureRules('file', 0, 0, 1920, 1080, true));
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'civility' => trans('validation.custom.civility'),
|
|
'first_name' => trans('validation.attributes.first_name'),
|
|
'last_name' => trans('validation.attributes.last_name'),
|
|
'society' => trans('validation.custom.society'),
|
|
'email' => trans('validation.attributes.email'),
|
|
'phone' => trans('validation.attributes.phone'),
|
|
'address' => trans('validation.attributes.address'),
|
|
'postal_code' => trans('validation.attributes.postal_code'),
|
|
'city' => trans('validation.attributes.city'),
|
|
'object' => trans('validation.custom.object'),
|
|
'product_name' => trans('validation.custom.product_name'),
|
|
'product_date_limit' => trans('validation.custom.product_date_limit'),
|
|
'product_barcode' => trans('validation.custom.product_barcode'),
|
|
'product_lot' => trans('validation.custom.product_lot'),
|
|
'product_date_consumption' => trans('validation.custom.product_date_consumption'),
|
|
'product_location' => trans('validation.custom.product_location'),
|
|
'message' => trans('validation.attributes.message'),
|
|
'accept_rules' => trans('validation.custom.accept_rules'),
|
|
'send_data' => trans('validation.custom.send_data'),
|
|
];
|
|
}
|
|
}
|