ldc-legaulois/app/Http/Requests/ContactFormRequest.php
2021-03-21 22:51:19 +01:00

67 lines
2.3 KiB
PHP

<?php
namespace App\Http\Requests;
use App\Enums\ContactFormCivility;
use App\Enums\ContactFormType;
use Illuminate\Foundation\Http\FormRequest;
class ContactFormRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
if ($this->type == ContactFormType::onepage()->value) {
app()->setLocale('nl');
}
return [
'civility' => [
'required',
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
function ($attribute, $value, $fail) {
if (!in_array($value, ContactFormCivility::toValues())) {
$fail(__('Veuillez choisir entre :values', [
'value' => implode(',', ContactFormCivility::toLabels())
]));
}
}
],
'type' => [
'required',
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
function ($attribute, $value, $fail) {
if (!in_array($value, ContactFormType::toValues())) {
$fail(__('Veuillez choisir entre :values', [
'value' => implode(',', ContactFormType::toLabels())
]));
}
}
],
'lastname' => 'required|min:2',
'firstname' => 'required|min:2',
'address' => 'required|min:4',
// TODO: The dns and spoof validators require the PHP intl extension. (présent sur prod ?)
'email' => 'required|email:rfc,dns,spoof',
'postal' => 'required|min:3|max:12',
'town' => 'required|min:3|max:90',
'phone' => 'required|min:8|max:14',
'onepagesubject' => 'sometimes|min:10|max:250',
'message' => 'required|min:20|max:1900',
'joinFile' => 'nullable|mimes:jpg,jpeg,png,pdf|max:3145728'
];
}
}