71 lines
2 KiB
PHP
71 lines
2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace App\Http\Requests\Bo\Ranges;
|
||
|
|
|
||
|
|
use App\Traits\Requests\HasPicture;
|
||
|
|
use Illuminate\Foundation\Http\FormRequest;
|
||
|
|
use Infrastructure\Adapters\Services\AppAdminAuthService;
|
||
|
|
|
||
|
|
class StoreRangeRequest extends FormRequest
|
||
|
|
{
|
||
|
|
use HasPicture;
|
||
|
|
|
||
|
|
public function __construct(
|
||
|
|
private readonly AppAdminAuthService $authService
|
||
|
|
) {
|
||
|
|
}
|
||
|
|
|
||
|
|
public function authorize(): bool
|
||
|
|
{
|
||
|
|
return $this->authService->check();
|
||
|
|
}
|
||
|
|
|
||
|
|
#[\Override]
|
||
|
|
protected function prepareForValidation(): void
|
||
|
|
{
|
||
|
|
$this->merge([
|
||
|
|
'status' => $this->boolean('status'),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** @return array<string,mixed> */
|
||
|
|
public function rules(): array
|
||
|
|
{
|
||
|
|
$maxWidth = 500;
|
||
|
|
$maxHeight = 500;
|
||
|
|
|
||
|
|
return array_merge(
|
||
|
|
[
|
||
|
|
'name' => ['required', 'string', 'min:2', 'max:45'],
|
||
|
|
'description' => ['nullable', 'string', 'min:2'],
|
||
|
|
'picture_alt' => ['required_with:picture', 'string', 'min:4', 'max:75'],
|
||
|
|
'picture_title' => ['required_with:picture', 'string', 'min:4', 'max:75'],
|
||
|
|
'status' => ['present', 'boolean:strict'],
|
||
|
|
],
|
||
|
|
$this->pictureRules(
|
||
|
|
'picture',
|
||
|
|
$maxWidth,
|
||
|
|
$maxHeight,
|
||
|
|
$maxWidth,
|
||
|
|
$maxHeight,
|
||
|
|
true
|
||
|
|
)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
#[\Override]
|
||
|
|
public function attributes(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'name' => trans('validation.attributes.name'),
|
||
|
|
'description' => trans('validation.attributes.description'),
|
||
|
|
'status' => trans('validation.custom.attributes.status'),
|
||
|
|
'picture' => trans('validation.attributes.image'),
|
||
|
|
'picture_alt' => trans('validation.custom.attributes.picture_alt'),
|
||
|
|
'picture_title' => trans('validation.custom.attributes.picture_title'),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|