ldc-wenn-dann-mit-respekt/app/Http/Requests/Bo/Sliders/StoreSliderRequest.php
Noah Lancien 222347d890 phpstan
2024-01-29 16:20:14 +01:00

100 lines
3.1 KiB
PHP

<?php
namespace App\Http\Requests\Bo\Sliders;
use App\Enums\Sliders\TypeEnum;
use Illuminate\Foundation\Http\FormRequest;
use App\Traits\Requests\HasPicture;
use Illuminate\Validation\Rules\Enum;
class StoreSliderRequest extends FormRequest
{
use HasPicture;
/**
* The model parameter name
*
* @var string
*/
protected $modelName = 'slider';
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize()
{
return auth('backend')->check();
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation()
{
$this->merge([
'link_new_tab' => $this->boolean('link_new_tab'),
'status' => $this->boolean('status'),
'publish_at' => $this->input('publish_at') ? \str_replace('T', ' ', $this->input('publish_at')) : null,
'unpublish_at' => $this->input('unpublish_at') ?
\str_replace('T', ' ', $this->input('unpublish_at')) :
null,
'locales' => \collect($this->input('locales'))->filter()->unique()->all()
]);
$this->mergePicture('picture');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$rules = [
'type' => [new Enum(TypeEnum::class)],
'title' => 'required|min:3|max:70',
'subtitle' => 'required|min:3|max:70',
'description' => 'required|string|min:15',
'link' => 'required|url',
'link_title' => 'required|min:3|max:255',
'link_new_tab' => 'required|boolean',
'picture_alt' => 'required|min:3|max:255',
'picture_title' => 'required|min:3|max:255',
'status' => 'required|boolean',
'locales' => 'required|array',
'locales.*' => ['required', \sprintf('in:%s', \implode(',', \config('app.locales')))],
'publish_at' => 'sometimes|nullable|date',
'unpublish_at' => 'sometimes|nullable|date'
];
return \array_merge(
$rules,
$this->pictureRules('picture', 1270, 930, 1270, 930, false),
);
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes()
{
return [
'type' => trans('type of slider'),
'title' => trans('title of the slide'),
'subtitle' => trans('subtitle of the slide'),
'description' => trans('description of the slide'),
'link' => trans('link of the slide'),
'link_title' => trans('title of link'),
'link_new_tab' => trans('open the link in the new tab'),
'picture' => trans('illustration'),
'picture_alt' => trans('alt attribute of the image'),
'picture_title' => trans('title attribute of the image'),
'status' => trans('status of the slide'),
];
}
}