ldc-volena/app/Http/Requests/Bo/Sections/UpdateSectionRequest.php

74 lines
1.8 KiB
PHP
Raw Normal View History

2023-11-17 16:07:28 +01:00
<?php
namespace App\Http\Requests\Bo\Sections;
use App\Http\Requests\Bo\UpdateMiniCrudRequest;
class UpdateSectionRequest extends UpdateMiniCrudRequest
{
/**
* The model parameter name
*
* @var string
*/
protected $modelName = 'section';
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize(): bool
{
return auth('backend')->check();
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
$rules = [
'h2_title' => 'required|between:3,255',
];
/** @var \App\Models\Section|null $section */
$section = $this->route('section');
if ($section) {
if ($section->section !== \App\Enums\Sections\PageSectionEnum::hire_grow) {
$rules = \array_merge($rules, [
'text' => 'present',
]);
}
if ($section->section->containsData()) {
$rules = \array_merge($rules, [
'data' => 'present|array',
'data.*' => 'required|array',
]);
}
2023-11-17 16:07:28 +01:00
}
return \array_merge(
parent::rules(),
$rules
);
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes()
{
return [
'h2_title' => __('validation.custom.h2_title'),
'text' => __('validation.attributes.content'),
'data' => trans('Valeurs du contenu spécifique'),
'data.*.value' => trans('Valeur du contenu spécifique'),
];
}
}