ldc-wenn-dann-mit-respekt/app/Http/Requests/Bo/Sliders/StoreSliderRequest.php
2023-05-10 18:46:44 +02:00

96 lines
2.8 KiB
PHP

<?php
namespace App\Http\Requests\Bo\Sliders;
use App\Enums\Sliders\TypeEnum;
use App\Http\Requests\Bo\UpdateMiniCrudRequest;
use App\Traits\Requests\HasPicture;
use Illuminate\Validation\Rules\Enum;
class StoreSliderRequest extends UpdateMiniCrudRequest
{
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->link_new_tab ? true : false,
'status' => $this->status ? true : false,
'publish_at' => $this->publish_at ? \str_replace('T', ' ', $this->publish_at) : null,
'unpublish_at' => $this->unpublish_at ? \str_replace('T', ' ', $this->unpublish_at) : null,
]);
$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',
'publish_at' => 'sometimes|nullable|date',
'unpublish_at' => 'sometimes|nullable|date'
];
return \array_merge(
$rules,
parent::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'),
];
}
}