69 lines
2.6 KiB
PHP
69 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class StoreClientLocationRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'client_id' => 'required|exists:clients,id',
|
|
'name' => 'nullable|string|max:191',
|
|
'address_line1' => 'nullable|string|max:255',
|
|
'address_line2' => 'nullable|string|max:255',
|
|
'postal_code' => 'nullable|string|max:20',
|
|
'city' => 'nullable|string|max:191',
|
|
'country_code' => 'nullable|string|size:2',
|
|
'gps_lat' => 'nullable|numeric|between:-90,90',
|
|
'gps_lng' => 'nullable|numeric|between:-180,180',
|
|
'is_default' => 'boolean',
|
|
];
|
|
}
|
|
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'client_id.required' => 'Le client est obligatoire.',
|
|
'client_id.exists' => 'Le client sélectionné n\'existe pas.',
|
|
'name.max' => 'Le nom ne peut pas dépasser 191 caractères.',
|
|
'address_line1.max' => 'L\'adresse ne peut pas dépasser 255 caractères.',
|
|
'address_line2.max' => 'Le complément d\'adresse ne peut pas dépasser 255 caractères.',
|
|
'postal_code.max' => 'Le code postal ne peut pas dépasser 20 caractères.',
|
|
'city.max' => 'La ville ne peut pas dépasser 191 caractères.',
|
|
'country_code.size' => 'Le code pays doit contenir 2 caractères.',
|
|
'gps_lat.numeric' => 'La latitude doit être un nombre.',
|
|
'gps_lat.between' => 'La latitude doit être comprise entre -90 et 90.',
|
|
'gps_lng.numeric' => 'La longitude doit être un nombre.',
|
|
'gps_lng.between' => 'La longitude doit être comprise entre -180 et 180.',
|
|
'is_default.boolean' => 'Le statut par défaut doit être vrai ou faux.',
|
|
];
|
|
}
|
|
|
|
public function withValidator($validator)
|
|
{
|
|
$validator->after(function ($validator) {
|
|
if (empty($this->address_line1) && empty($this->postal_code) && empty($this->city)) {
|
|
$validator->errors()->add(
|
|
'general',
|
|
'Au moins un champ d\'adresse (adresse, code postal ou ville) doit être renseigné.'
|
|
);
|
|
}
|
|
});
|
|
}
|
|
}
|