2023-08-21 15:24:32 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Fo\Customers;
|
|
|
|
|
|
|
|
|
|
use App\Enums\CustomerTypeEnum;
|
|
|
|
|
use App\Rules\Adult;
|
|
|
|
|
use BadMethodCallException;
|
|
|
|
|
use Illuminate\Contracts\Validation\Validator;
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
2026-03-19 11:21:49 +01:00
|
|
|
use Illuminate\Validation\Rules\Enum;
|
2023-08-21 15:24:32 +02:00
|
|
|
use Illuminate\Validation\Rules\Password;
|
|
|
|
|
use LDC\LDCCRM\Enums\Country;
|
|
|
|
|
|
|
|
|
|
class CreateAccountRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Get the validator
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Contracts\Validation\Validator
|
|
|
|
|
*/
|
|
|
|
|
public function getValidator(): Validator
|
|
|
|
|
{
|
|
|
|
|
$this->prepareForValidation();
|
|
|
|
|
|
|
|
|
|
return $this->getValidatorInstance();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public function authorize()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepare the data for validation.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function prepareForValidation()
|
|
|
|
|
{
|
|
|
|
|
$this->merge([
|
|
|
|
|
'phone' => $this->phone,
|
|
|
|
|
'opt_in' => $this->opt_in ? true : false,
|
|
|
|
|
'eleveur_porcs' => $this->boolean('eleveur.eleveur_porcs') ? true : false,
|
|
|
|
|
'eleveur_volailles' => $this->boolean('eleveur.eleveur_volailles') ? true : false,
|
|
|
|
|
'eleveur_bovins' => $this->boolean('eleveur.eleveur_bovins') ? true : false,
|
|
|
|
|
'stockage_aplat' => $this->boolean('stockage.stockage_aplat') ? true : false,
|
|
|
|
|
'stockage_cellule' => $this->boolean('stockage.stockage_cellule') ? true : false,
|
|
|
|
|
'role' => \ctype_digit($this->user_cat) ? \intval($this->user_cat) : $this->user_cat,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function rules()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$requiredIfRoleIsPro = 'sometimes';
|
|
|
|
|
try {
|
|
|
|
|
$role = $this->customer ? $this->customer->role : CustomerTypeEnum::make($this->role);
|
2026-03-19 11:21:49 +01:00
|
|
|
if ($role->equals(CustomerTypeEnum::professional)) {
|
2023-08-21 15:24:32 +02:00
|
|
|
$requiredIfRoleIsPro = 'required';
|
|
|
|
|
}
|
2026-03-19 11:21:49 +01:00
|
|
|
} catch (BadMethodCallException | \TypeError $e) {
|
2023-08-21 15:24:32 +02:00
|
|
|
$requiredIfRoleIsPro = 'sometimes';
|
|
|
|
|
}
|
|
|
|
|
return [
|
|
|
|
|
'lastname' => 'required|string|max:255',
|
|
|
|
|
'firstname' => 'required|string|max:255',
|
|
|
|
|
'phone' => 'nullable|max:255',
|
|
|
|
|
'address' => 'required|string|min:1|max:255',
|
|
|
|
|
'postcode' => 'required|string|min:1',
|
|
|
|
|
'city' => 'required|string|min:1|max:255',
|
|
|
|
|
'birth_date' => ['required', new Adult(trans('Vous devez être majeur pour vous inscrire.'))],
|
|
|
|
|
'email' => [
|
|
|
|
|
'required', 'email:rfc,dns,spoof', 'max:255',
|
|
|
|
|
'unique:customers,email',
|
|
|
|
|
],
|
|
|
|
|
'password' => [
|
|
|
|
|
'required', 'confirmed', Password::min(8)->mixedCase()->numbers()->symbols()
|
|
|
|
|
],
|
|
|
|
|
'ok_cgv' => 'accepted',
|
|
|
|
|
'opt_in' => 'required|boolean',
|
|
|
|
|
|
|
|
|
|
// * Spécific jeusselin
|
2026-03-19 11:21:49 +01:00
|
|
|
'role' => ['required', new Enum(CustomerTypeEnum::class)],
|
2023-08-21 15:24:32 +02:00
|
|
|
|
|
|
|
|
'social_denomination' => "{$requiredIfRoleIsPro}|max:255",
|
|
|
|
|
'tech_commercial' => "{$requiredIfRoleIsPro}|string|max:255",
|
|
|
|
|
'siret' => "{$requiredIfRoleIsPro}|string|max:255",
|
|
|
|
|
'numtva' => "{$requiredIfRoleIsPro}|string|max:255",
|
|
|
|
|
'certiphyto' => "{$requiredIfRoleIsPro}|string|max:255",
|
|
|
|
|
'certiphyto_date' => "{$requiredIfRoleIsPro}|string|max:255",
|
|
|
|
|
'eleveur' => "{$requiredIfRoleIsPro}|array|min:1",
|
|
|
|
|
'eleveur_porcs' => "required_with:eleveur|boolean",
|
|
|
|
|
'eleveur_volailles' => "required_with:eleveur|boolean",
|
|
|
|
|
'eleveur_bovins' => "required_with:eleveur|boolean",
|
|
|
|
|
'capacite_stockage' => "{$requiredIfRoleIsPro}|string|max:255",
|
|
|
|
|
'temps_chargement' => "{$requiredIfRoleIsPro}|string|max:255",
|
|
|
|
|
'stockage' => "{$requiredIfRoleIsPro}|array|min:1",
|
|
|
|
|
'stockage_aplat' => "required_with:stockage|boolean",
|
|
|
|
|
'stockage_cellule' => "required_with:stockage|boolean",
|
|
|
|
|
'adress_chargement' => "present|nullable|string|max:255",
|
|
|
|
|
'optional_contact' => "present|nullable|string|max:255",
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get custom attributes for validator errors.
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function attributes()
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'lastname' => trans('nom'),
|
|
|
|
|
'firstname' => trans('prénom'),
|
|
|
|
|
'phone' => trans('téléphone'),
|
|
|
|
|
'address' => trans('adresse'),
|
|
|
|
|
'postcode' => trans('code postal'),
|
|
|
|
|
'city' => trans('ville'),
|
|
|
|
|
'birth_date' => trans('date de naissance'),
|
|
|
|
|
'email' => trans('email'),
|
|
|
|
|
'password' => trans('mot de passe'),
|
|
|
|
|
'ok_cgv' => trans('conditions d\'utilisation'),
|
|
|
|
|
'opt_in' => trans('newsletter'),
|
|
|
|
|
|
|
|
|
|
'role' => trans('êtes-vous un agriculteur'),
|
|
|
|
|
'social_denomination' => trans('dénomination sociale'),
|
|
|
|
|
'tech_commercial' => trans('technico commercial'),
|
|
|
|
|
'siret' => trans('siret'),
|
|
|
|
|
'certiphyto_date' => trans('date de validité'),
|
|
|
|
|
'numtva' => trans('numéro de tva'),
|
|
|
|
|
'certiphyto' => trans('numéro de certiphyto'),
|
|
|
|
|
'certiphyto_date' => trans('numéro de certiphyto'),
|
|
|
|
|
'eleveur' => trans('éleveur de'),
|
|
|
|
|
'capacite_stockage' => trans('capacité de stockage'),
|
|
|
|
|
'temps_chargement' => trans('temps de chargement'),
|
|
|
|
|
'stockage' => trans('type de stockage'),
|
|
|
|
|
'adress_chargement' => trans('adresse de chargement'),
|
|
|
|
|
'optional_contact' => trans('contact à joindre'),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get custom messages for validator errors.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function messages()
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'phone.phone' => trans('Le champ :attribute est invalide, il accepte les numéros des
|
2026-03-19 11:21:49 +01:00
|
|
|
pays suivants :countries.', ['countries' => Country::france->label()]),
|
2023-08-21 15:24:32 +02:00
|
|
|
'country.in' => trans('Le champ :attribute est invalide, il accepte les pays
|
2026-03-19 11:21:49 +01:00
|
|
|
suivants :countries.', ['countries' => Country::france->label()]),
|
2023-08-21 15:24:32 +02:00
|
|
|
'email.unique' => trans('Un compte existe déjà avec cette adresse.'),
|
|
|
|
|
'ok_cgv.accepted' => trans('Vous devez accepter les conditions d\'utilisation du site pour continuer.')
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|