82 lines
3 KiB
PHP
82 lines
3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\MenuNodeData;
|
|
|
|
use App\Traits\Requests\HasPicture;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use LVR\Colour\Hex;
|
|
|
|
class UpdateMenuNodeDataRequest extends FormRequest
|
|
{
|
|
use HasPicture;
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return Gate::check('update', $this->route('menu_node_data'));
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function prepareForValidation(): void
|
|
{
|
|
if ($this->has('text')) {
|
|
$this->merge(['text' => str($this->input('text'))->value()]);
|
|
}
|
|
if ($this->has('text_color')) {
|
|
$this->merge(['text_color' => str($this->input('text_color'))->value()]);
|
|
}
|
|
if ($this->has('link_target')) {
|
|
$this->merge(['link_target' => $this->boolean('link_target')]);
|
|
}
|
|
if ($this->has('link_status')) {
|
|
$this->merge(['link_status' => $this->boolean('link_status')]);
|
|
}
|
|
if ($this->has('picture_status')) {
|
|
$this->merge(['picture_status' => $this->boolean('picture_status')]);
|
|
}
|
|
if ($this->has('picture')) {
|
|
$this->mergePicture('picture');
|
|
}
|
|
if ($this->has('background_picture')) {
|
|
$this->mergePicture('background_picture');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string,\Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
'sub_label' => 'sometimes|required|string|min:4|max:255',
|
|
'title' => 'sometimes|required|string|min:4|max:255',
|
|
'text' => 'sometimes|required|string|max:255',
|
|
'text_color' => ['sometimes', 'required', new Hex()],
|
|
'link_url' => 'sometimes|required|string|max:255',
|
|
'link_title' => 'sometimes|required|string|between:3,255',
|
|
'link_target' => 'sometimes|present|boolean',
|
|
'link_status' => 'sometimes|present|boolean',
|
|
'picture_alt' => 'sometimes|required|string|between:3,255',
|
|
'picture_title' => 'sometimes|required|string|between:3,255',
|
|
'picture_status' => 'sometimes|required|boolean',
|
|
'background_picture_alt' => 'sometimes|required|string|between:3,255',
|
|
'background_picture_title' => 'sometimes|required|string|between:3,255',
|
|
];
|
|
return \array_merge(
|
|
$rules,
|
|
$this->pictureRules('picture', 180, 228, 180, 228, nullable: false, sometimes: true),
|
|
$this->pictureRules('background_picture', 500, 231, 500, 231, nullable: false, sometimes: true),
|
|
);
|
|
}
|
|
}
|