2024-04-04 13:00:12 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Bo\MainSlides;
|
|
|
|
|
|
|
|
|
|
use App\Models\MainSlide;
|
2026-09-25 16:25:31 +02:00
|
|
|
use App\Rules\Hex;
|
2024-04-04 13:00:12 +02:00
|
|
|
use App\Traits\Requests\HasPicture;
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
|
|
|
|
|
|
class StoreMainSlideRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
use HasPicture;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
|
*/
|
|
|
|
|
public function authorize(): bool
|
|
|
|
|
{
|
|
|
|
|
return Gate::check('create', MainSlide::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepare the data for validation.
|
|
|
|
|
*/
|
|
|
|
|
protected function prepareForValidation(): void
|
|
|
|
|
{
|
|
|
|
|
$this->merge([
|
|
|
|
|
'button_1_status' => $this->boolean('button_1_status'),
|
|
|
|
|
'button_1_target' => $this->boolean('button_1_target'),
|
|
|
|
|
'button_2_status' => $this->boolean('button_2_status'),
|
|
|
|
|
'button_2_target' => $this->boolean('button_2_target'),
|
|
|
|
|
'new' => $this->boolean('new'),
|
2024-10-21 12:01:23 +02:00
|
|
|
'published' => $this->boolean('published'),
|
2024-04-04 13:00:12 +02:00
|
|
|
]);
|
|
|
|
|
$this->mergePicture('picture');
|
|
|
|
|
$this->mergePicture('background');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*/
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
$rules = [
|
|
|
|
|
'title' => 'required|string|between:3,255',
|
|
|
|
|
'subtitle' => 'required|string|between:3,255',
|
|
|
|
|
'background_alt' => 'required_with:background|nullable|between:3,255',
|
|
|
|
|
'background_title' => 'required_with:background|nullable|between:3,255',
|
|
|
|
|
'picture_alt' => 'required_with:picture|nullable|between:3,255',
|
|
|
|
|
'picture_title' => 'required_with:picture|nullable|between:3,255',
|
2024-04-15 10:34:58 +02:00
|
|
|
'approach_id' => 'sometimes|nullable|integer|exists:approaches,id',
|
2024-04-04 13:00:12 +02:00
|
|
|
'button_1_status' => 'required|boolean',
|
|
|
|
|
'button_1_text' => 'required_if_accepted:button_1_status|string|nullable|between:3,255',
|
|
|
|
|
'button_1_url' => 'required_if_accepted:button_1_status|string|nullable|url:http,https',
|
|
|
|
|
'button_1_target' => 'required_if_accepted:button_1_status|boolean',
|
|
|
|
|
'button_2_status' => 'required|boolean',
|
|
|
|
|
'button_2_text' => 'required_if_accepted:button_2_status|string|nullable|between:3,255',
|
|
|
|
|
'button_2_url' => 'required_if_accepted:button_2_status|string|nullable|url:http,https',
|
|
|
|
|
'button_2_target' => 'required_if_accepted:button_2_status|boolean',
|
|
|
|
|
'color_block' => ['required', new Hex()],
|
|
|
|
|
'button_1_color_text' => ['required_if_accepted:button_1_status', new Hex()],
|
|
|
|
|
'button_1_color_background' => ['required_if_accepted:button_1_status', new Hex()],
|
|
|
|
|
'button_2_color_text' => ['required_if_accepted:button_2_status', new Hex()],
|
|
|
|
|
'button_2_color_background' => ['required_if_accepted:button_2_status', new Hex()],
|
|
|
|
|
'new' => 'required|boolean',
|
2024-10-21 12:01:23 +02:00
|
|
|
'published' => 'required|boolean',
|
|
|
|
|
'published_at' => 'nullable|date',
|
|
|
|
|
'unpublished_at' => 'nullable|date|after:published_at',
|
2024-04-04 13:00:12 +02:00
|
|
|
];
|
2026-09-25 16:25:31 +02:00
|
|
|
|
2024-04-04 13:00:12 +02:00
|
|
|
return \array_merge(
|
|
|
|
|
$rules,
|
|
|
|
|
$this->pictureRules('background', 1440, 700, 1440, 700),
|
|
|
|
|
$this->pictureRules('picture', 200, 300, 200, 300, true),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get custom attributes for validator errors.
|
|
|
|
|
*/
|
|
|
|
|
public function attributes(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'title' => trans('validation.attributes.title'),
|
|
|
|
|
'subtitle' => trans('validation.custom.subtitle'),
|
|
|
|
|
'background' => trans('validation.custom.background'),
|
2024-04-19 10:08:36 +02:00
|
|
|
'background_alt' => trans('validation.custom.attribute_alt'),
|
|
|
|
|
'background_title' => trans('validation.custom.attribute_title'),
|
2024-04-04 13:00:12 +02:00
|
|
|
'picture' => trans('validation.attributes.image'),
|
2024-04-19 10:08:36 +02:00
|
|
|
'picture_alt' => trans('validation.custom.attribute_alt'),
|
|
|
|
|
'picture_title' => trans('validation.custom.attribute_title'),
|
2024-04-04 13:00:12 +02:00
|
|
|
'button_1_text' => trans('validation.custom.button_text') . ' n°1',
|
|
|
|
|
'button_1_url' => trans('validation.custom.button_url') . ' n°1',
|
|
|
|
|
'button_1_status' => trans('validation.custom.button_status') . ' n°1',
|
|
|
|
|
'button_1_target' => trans('validation.custom.button_target') . ' n°1',
|
|
|
|
|
'button_2_text' => trans('validation.custom.button_text') . ' n°2',
|
|
|
|
|
'button_2_url' => trans('validation.custom.button_url') . ' n°2',
|
|
|
|
|
'button_2_status' => trans('validation.custom.button_status') . ' n°2',
|
|
|
|
|
'button_2_target' => trans('validation.custom.button_target') . ' n°2',
|
|
|
|
|
'color_block' => trans('validation.custom.color_block'),
|
|
|
|
|
'button_1_color_text' => trans('validation.custom.button_color_text') . ' n°1',
|
|
|
|
|
'button_1_color_background' => trans('validation.custom.button_color_background') . ' n°1',
|
|
|
|
|
'button_2_color_text' => trans('validation.custom.button_color_text') . ' n°2',
|
|
|
|
|
'button_2_color_background' => trans('validation.custom.button_color_background') . ' n°2',
|
|
|
|
|
'new' => trans('validation.custom.new'),
|
|
|
|
|
'published' => trans('validation.custom.published'),
|
2024-10-21 12:01:23 +02:00
|
|
|
'published_at' => trans('validation.custom.published_at'),
|
|
|
|
|
'unpublished_at' => trans('validation.custom.unpublished_at'),
|
2024-04-04 13:00:12 +02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|