2023-04-17 17:46:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Bo\Settings;
|
|
|
|
|
|
|
|
|
|
use App\Traits\Requests\HasPicture;
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
2023-04-18 12:43:39 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2023-04-17 17:46:20 +02:00
|
|
|
|
|
|
|
|
class UpdateSettingRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
use HasPicture;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public function authorize()
|
|
|
|
|
{
|
2023-04-18 12:43:39 +02:00
|
|
|
if (
|
|
|
|
|
$this->key === "Button1" ||
|
|
|
|
|
$this->key === "Button2" ||
|
|
|
|
|
$this->key === "Button3" ||
|
|
|
|
|
$this->key === "ShowIsActive"
|
|
|
|
|
) {
|
|
|
|
|
return auth('backend')->check();
|
|
|
|
|
} else {
|
|
|
|
|
return (auth('backend')->check() && Auth::user()->role === 1);
|
|
|
|
|
}
|
2023-04-17 17:46:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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'),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|