96 lines
3 KiB
PHP
96 lines
3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\Concepts;
|
|
|
|
use App\Enums\Concepts\ColorsEnum;
|
|
use App\Http\Requests\Bo\UpdateMiniCrudRequest;
|
|
use App\Models\Concept;
|
|
use App\Traits\Requests\HasPicture;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Validation\Rules\Enum;
|
|
|
|
class StoreConceptRequest extends UpdateMiniCrudRequest
|
|
{
|
|
use HasPicture;
|
|
|
|
/**
|
|
* The model parameter name
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $modelName = 'concept';
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return (auth('backend')->check() && Concept::count() < 9);
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'slug' => Str::slug(strip_tags($this->input('name')))
|
|
]);
|
|
$this->mergePicture('picture');
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
'seo_title' => 'required|min:3|max:70',
|
|
'seo_description' => 'required|min:50|max:160',
|
|
'name' => 'required|min:3|max:70',
|
|
'slug' => 'unique_translation:concepts',
|
|
'title' => 'required|min:3|max:70',
|
|
'title_background_color' => ['required', new Enum(ColorsEnum::class)],
|
|
'subtitle' => 'required|min:3|max:70',
|
|
'description' => 'required|string|min:15',
|
|
'data' => 'present|array',
|
|
'data.*' => 'required|array',
|
|
'picture_alt' => 'required|min:3|max:255',
|
|
'picture_title' => 'required|min:3|max:255',
|
|
];
|
|
return \array_merge(
|
|
parent::rules(),
|
|
$rules,
|
|
$this->pictureRules('picture', 1512, 354, 1512, 354, false),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes()
|
|
{
|
|
return [
|
|
'seo_title' => trans('titre') . ' seo',
|
|
'seo_description' => trans('description') . ' seo',
|
|
'name' => trans('name of the concept'),
|
|
'slug' => trans('slug of the concept'),
|
|
'title' => trans('title of the concept'),
|
|
'subtitle' => trans('subtitle of the concept'),
|
|
'description' => trans('description of the concept'),
|
|
'data' => trans('values of the data'),
|
|
'data.*.value' => trans('value of the data'),
|
|
'picture' => trans('illustration'),
|
|
'picture_alt' => trans('alt attribute of the image'),
|
|
'picture_title' => trans('title attribute of the image'),
|
|
];
|
|
}
|
|
}
|