ldc-legaulois/app/Http/Requests/ContactFormRequest.php
2021-02-15 17:48:49 +01:00

61 lines
1.9 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()
{
return [
'civility' => [
'required',
function ($attribute, $value, $fail) {
if (!in_array($value, ContactFormCivility::toValues())) {
$fail(__('Veuillez choisir entre :values', [
'value' => implode(',', ContactFormCivility::toLabels())
]));
}
}
],
'type' => [
'required',
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',
'message' => 'required|min:20|max:1900',
'joinFile' => 'nullable|mimes:jpg,jpeg,png,pdf|max:3145728'
];
}
}