ldc-tregalette/app/Http/Requests/Bo/Games/StoreGameRequest.php
Vincent BRIDIER 6d4500c360 Bump CRM V4
2024-07-16 15:55:49 +00:00

119 lines
4.2 KiB
PHP

<?php
namespace App\Http\Requests\Bo\Games;
use App\Traits\Requests\HasPicture;
use Closure;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;
class StoreGameRequest 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()
{
$this->merge([
'published' => $this->published ? true : false,
'button_status' => $this->button_status ? true : false,
'button_new_tab' => $this->button_status ? true : false,
]);
$this->mergePicture('picture');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
$rules = [
'title_line1' => 'required|string|between:3,255',
'title_line2' => 'required|string|between:3,255',
'picture_alt' => 'required|string|between:3,255',
'picture_title' => 'required|string|between:3,255',
'text' => [
'required',
'string',
'min:15',
// phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
function (string $attribute, mixed $value, Closure $fail) {
// phpcs:enable
if (Str::wordCount(\strip_tags($value)) > 32) {
$fail(trans('validation.max_words', [
'attribute' => trans('validation.attributes.text'),
'count' => '32'
]));
}
}
],
'button_status' => 'required|boolean',
'button_label' => 'required|string|between:3,255',
'button_url' => 'required|url',
'button_new_tab' => 'required|boolean',
'published' => 'required|boolean',
'publish_at' => 'nullable|date',
'unpublish_at' => 'nullable|date|after:publish_at',
];
return \array_merge(
$rules,
$this->pictureRules('picture', 585, 415, 585, 415, false)
);
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
'title_line1' => trans('validation.custom.title_line1'),
'title_line2' => trans('validation.custom.title_line2'),
'picture_alt' => trans('validation.custom.attribute_alt'),
'picture_title' => trans('validation.custom.attribute_title'),
'text' => trans('validation.attributes.text'),
'button_status' => trans(':field1 :inter:field2', [
'field1' => trans('crud.minicrud.visibility_label'),
'inter' => trans('validation.custom.of_the.male'),
'field2' => trans('validation.custom.button'),
]),
'button_label' => trans(':field :inter:model', [
'field' => trans('validation.custom.label'),
'inter' => trans('validation.custom.of_the.male'),
'model' => trans('validation.custom.button'),
]),
'button_url' => trans(':field :inter:model', [
'field' => trans('validation.custom.url'),
'inter' => trans('validation.custom.of_the.male'),
'model' => trans('validation.custom.button'),
]),
'button_new_tab' => trans(':field1 :inter:field2', [
'field1' => trans('validation.custom.target'),
'inter' => trans('validation.custom.of_the.male'),
'field2' => trans('validation.custom.button'),
]),
'published' => trans('validation.custom.activated'),
'publish_at' => trans('validation.custom.publish_at'),
'unpublish_at' => trans('validation.custom.unpublish_at'),
];
}
}