162 lines
7.4 KiB
PHP
162 lines
7.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\Sites;
|
|
|
|
use App\Traits\Requests\HasPicture;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Str;
|
|
|
|
class StoreSiteRequest extends FormRequest
|
|
{
|
|
use HasPicture;
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return auth('backend')->check();
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'published' => $this->boolean('published'),
|
|
'pictos' => \collect($this->input('pictos'))->all(),
|
|
]);
|
|
$this->mergePicture('logo');
|
|
$this->mergePicture('picture_1');
|
|
$this->mergePicture('picture_2');
|
|
$this->mergePicture('picture_3');
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
'seo_title' => 'required|between:45,70',
|
|
'seo_description' => 'required|between:50,160',
|
|
'name' => 'required|string|between:3,100',
|
|
'description' => 'required|string|between:3,255',
|
|
'description_2' => 'nullable|string|between:3,255',
|
|
'employees' => 'required|numeric|min:0',
|
|
'pictos' => 'present|array',
|
|
'pictos.*' => 'required|integer',
|
|
'address' => 'required|string|between:3,255',
|
|
'phone_number' => 'required|string|between:10,20',
|
|
'access_line' => 'present|array',
|
|
'access_line.*' => 'nullable|string|between:3,255',
|
|
'director_name' => 'nullable|string|between:3,255',
|
|
'director_speach' => 'required|string|min:15',
|
|
'employee_name' => 'nullable|string|between:3,255',
|
|
'employee_function' => 'nullable|string|between:3,255',
|
|
'employee_speach' => 'nullable|string|min:15',
|
|
'highlights' => 'nullable|string|min:15',
|
|
'latitude' => 'required|numeric|between:-90,90',
|
|
'longitude' => 'required|numeric|between:-180,180',
|
|
'logo_alt' => 'required|string|between:3,255',
|
|
'logo_title' => 'required|string|between:3,255',
|
|
'picture_1_alt' => 'required|string|between:3,255',
|
|
'picture_1_title' => 'required|string|between:3,255',
|
|
'picture_2_alt' => 'required_with:picture_2|nullable|string|between:3,255',
|
|
'picture_2_title' => 'required_with:picture_2|nullable|string|between:3,255',
|
|
'picture_3_alt' => 'required_with:picture_3|nullable|string|between:3,255',
|
|
'picture_3_title' => 'required_with:picture_3|nullable|string|between:3,255',
|
|
'logos' => 'nullable|array',
|
|
'logos.*.id' => 'required|exists:logos,id',
|
|
|
|
|
|
];
|
|
return \array_merge(
|
|
$rules,
|
|
$this->pictureRules('logo', 1000, 727, 1000, 727, false),
|
|
$this->pictureRules('picture_1', 1000, 562, 1000, 562, false),
|
|
$this->pictureRules('picture_2', 1000, 562, 1000, 562, true),
|
|
$this->pictureRules('picture_3', 1000, 562, 1000, 562, true),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'seo_title' => trans('validation.custom.seo_title'),
|
|
'seo_description' => trans('validation.custom.seo_description'),
|
|
'name' => trans('validation.attributes.name'),
|
|
'description' => trans('validation.custom.description'),
|
|
'description_2' => trans('validation.custom.description_2'),
|
|
'employees' => trans('validation.custom.employees_count'),
|
|
'pictos' => Str::plural(trans('validation.custom.picto')),
|
|
'pictos.*' => trans('validation.custom.picto'),
|
|
'address' => trans('validation.attributes.address'),
|
|
'phone_number' => trans('validation.attributes.phone'),
|
|
'access_line' => trans('validation.custom.access_line'),
|
|
'access_line.*' => trans('ligne d\'accès au site'),
|
|
'director_name' => trans('validation.custom.director_name'),
|
|
'director_speach' => trans('validation.custom.director_speach'),
|
|
'employee_name' => trans('validation.custom.employee_name'),
|
|
'employee_function' => trans('validation.custom.employee_function'),
|
|
'employee_speach' => trans('validation.custom.employee_speach'),
|
|
'highlights' => Str::plural(trans('validation.custom.highlight')),
|
|
'latitude' => trans('validation.custom.latitude'),
|
|
'longitude' => trans('validation.custom.longitude'),
|
|
'logos' => Str::plural(trans('models.classes.logo')),
|
|
'logos.*' => trans('models.classes.logo'),
|
|
'logo_alt' => trans(':field :inter:model', [
|
|
'field' => trans('validation.custom.alt_attribute'),
|
|
'inter' => trans('validation.custom.of_the.male'),
|
|
'model' => trans('validation.custom.logo'),
|
|
]),
|
|
'logo_title' => trans(':field :inter:model', [
|
|
'field' => trans('validation.custom.title_attribute'),
|
|
'inter' => trans('validation.custom.of_the.male'),
|
|
'model' => trans('validation.custom.logo'),
|
|
]),
|
|
'picture_1_alt' => trans(':field :inter:model', [
|
|
'field' => trans('validation.custom.alt_attribute'),
|
|
'inter' => trans('validation.custom.of_the.vowel'),
|
|
'model' => trans('validation.custom.picture_1'),
|
|
]),
|
|
'picture_1_title' => trans(':field :inter:model', [
|
|
'field' => trans('validation.custom.title_attribute'),
|
|
'inter' => trans('validation.custom.of_the.vowel'),
|
|
'model' => trans('validation.custom.picture_1'),
|
|
]),
|
|
'picture_2_alt' => trans(':field :inter:model', [
|
|
'field' => trans('validation.custom.alt_attribute'),
|
|
'inter' => trans('validation.custom.of_the.vowel'),
|
|
'model' => trans('validation.custom.picture_2'),
|
|
]),
|
|
'picture_2_title' => trans(':field :inter:model', [
|
|
'field' => trans('validation.custom.title_attribute'),
|
|
'inter' => trans('validation.custom.of_the.vowel'),
|
|
'model' => trans('validation.custom.picture_2'),
|
|
]),
|
|
'picture_3_alt' => trans(':field :inter:model', [
|
|
'field' => trans('validation.custom.alt_attribute'),
|
|
'inter' => trans('validation.custom.of_the.vowel'),
|
|
'model' => trans('validation.custom.picture_3'),
|
|
]),
|
|
'picture_3_title' => trans(':field :inter:model', [
|
|
'field' => trans('validation.custom.title_attribute'),
|
|
'inter' => trans('validation.custom.of_the.vowel'),
|
|
'model' => trans('validation.custom.picture_3'),
|
|
]),
|
|
];
|
|
}
|
|
}
|