ldc-showroom-bo/app/Http/Requests/Bo/Settings/UpdateSettingsRequest.php
2025-07-09 15:28:33 +02:00

74 lines
2.1 KiB
PHP

<?php
namespace App\Http\Requests\Bo\Settings;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
use App\Rules\Hex;
class UpdateSettingsRequest extends FormRequest
{
use HasPicture;
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize(): bool
{
return Gate::allows('update', $this->route('settings'));
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation(): void
{
$this->mergePicture('logo');
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
*/
public function rules(): array
{
$numberOfLocales = count(config('app.locales'));
$rules = [
'locales' => "required|array|between:1,$numberOfLocales",
'sub_title' => "required|array|between:0,$numberOfLocales",
'sub_title.*' => 'nullable|min:2|max:110',
'footer_phrase' => "required|array|between:1,$numberOfLocales",
'footer_phrase.*' => 'required|min:2|max:110',
'color' => ['required', new Hex()],
'home_timeout' => 'required|numeric|min:20|max:900',
];
return \array_merge(
$rules,
$this->pictureRules('logo', 420, 500, 420, 500, false)
);
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
'locales' => \trans('validation.custom.locales'),
'color' => \trans('validation.custom.color'),
'logo' => \trans('validation.custom.logo'),
'home_timeout' => \trans('validation.custom.home_timeout'),
'sub_title.*' => \trans('validation.custom.sub_title'),
'footer_phrase.*' => \trans('validation.custom.footer_phrase'),
];
}
}