2024-04-12 10:18:11 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Bo\MenuNodeData;
|
|
|
|
|
|
|
|
|
|
use App\Traits\Requests\HasPicture;
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
2024-04-16 16:53:38 +02:00
|
|
|
if ($this->has('text')) {
|
|
|
|
|
$this->merge(['text' => str($this->input('text'))->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');
|
|
|
|
|
}
|
2024-04-12 10:18:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*
|
|
|
|
|
* @return array<string,\Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
|
|
|
*/
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
$rules = [
|
2024-04-16 16:53:38 +02:00
|
|
|
'title' => 'sometimes|required|string|min:4|max:255',
|
|
|
|
|
'text' => 'sometimes|required|string|max:255',
|
|
|
|
|
'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|string|boolean',
|
|
|
|
|
'background_picture_alt' => 'sometimes|required|string|between:3,255',
|
|
|
|
|
'background_picture_title' => 'sometimes|required|string|between:3,255',
|
2024-04-12 10:18:11 +02:00
|
|
|
];
|
|
|
|
|
return \array_merge(
|
|
|
|
|
$rules,
|
2024-04-16 16:53:38 +02:00
|
|
|
$this->pictureRules('picture', 180, 228, 180, 228, nullable: false, sometimes: true),
|
|
|
|
|
$this->pictureRules('background_picture', 500, 231, 500, 231, nullable: false, sometimes: true),
|
2024-04-12 10:18:11 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|