ldc-com-app-bo/app/Http/Requests/Bo/Settings/UpdateSettingRequest.php
2023-04-18 10:19:33 +02:00

79 lines
1.8 KiB
PHP

<?php
namespace App\Http\Requests\Bo\Settings;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
class UpdateSettingRequest extends FormRequest
{
use HasPicture;
/**
* 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()
{
if ($this->key === "ShowIsActive") {
$this->merge(['value' => $this->value ? "true" : "false"]);
}
if (
$this->key === "SquaredLogo" ||
$this->key === "RectangleLogo" ||
$this->key === "BackgroundImage" ||
$this->key === "HomeButtonImage"
) {
$this->mergePicture('value');
}
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$rules = [
'value' => 'required|string|min:1',
];
if (
$this->key === "SquaredLogo" ||
$this->key === "RectangleLogo" ||
$this->key === "BackgroundImage" ||
$this->key === "HomeButtonImage"
) {
return \array_merge(
$rules,
$this->pictureRules('value', true, 100, 100, 1920, 1200),
);
} else {
return $rules;
}
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes()
{
return [
'key' => \trans('clé'),
'value' => \trans('valeur'),
];
}
}