ldc-wenn-dann-mit-respekt/app/Http/Requests/Bo/Ranges/StoreRangeRequest.php

71 lines
1.8 KiB
PHP

<?php
namespace App\Http\Requests\Bo\Ranges;
use App\Enums\Ranges\PictoEnum;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;
use Illuminate\Validation\Rules\Enum;
class StoreRangeRequest 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([
'slug' => Str::slug(strip_tags($this->input('label'))),
'status' => $this->boolean('status'),
]);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [
'seo_title' => 'required|min:3|max:70',
'seo_description' => 'required|min:50|max:160',
'label' => 'required|min:3|max:255',
'slug' => 'unique_translation:ranges',
'picto' => [new Enum(PictoEnum::class)],
'status' => 'required|boolean'
];
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
'seo_title' => trans('title') . ' seo',
'seo_description' => trans('description') . ' seo',
'label' => trans('label'),
'picto' => trans('picto'),
'slug' => trans('slug'),
'status' => trans('publish')
];
}
}