2024-01-03 15:30:10 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Bo\StaticPages;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
|
|
class UpdateStaticPageRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public function authorize(): bool
|
|
|
|
|
{
|
|
|
|
|
return Gate::check('update', $this->route('static_page'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepare the data for validation.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function prepareForValidation(): void
|
|
|
|
|
{
|
2025-07-15 15:59:36 +02:00
|
|
|
/** @var \App\Models\StaticPage $staticPageModel */
|
|
|
|
|
$staticPageModel = request()->route()->parameter('static_page');
|
2024-01-03 15:30:10 +01:00
|
|
|
$this->merge([
|
2025-07-15 15:59:36 +02:00
|
|
|
'content' => (in_array($staticPageModel->type, \App\Enums\StaticPageType::getEditableContentPages()))
|
|
|
|
|
? Str::of($this->input('content'))->value()
|
|
|
|
|
: null
|
2024-01-03 15:30:10 +01:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*
|
|
|
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
|
|
|
*/
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'seo_title' => 'required|min:45|max:70',
|
|
|
|
|
'seo_description' => 'required|min:50|max:160',
|
|
|
|
|
'title' => 'required|min:3|max:255',
|
2025-07-15 15:59:36 +02:00
|
|
|
'content' => 'present|string|nullable'
|
2024-01-03 15:30:10 +01:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get custom attributes for validator errors.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function attributes(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'seo_title' => trans('validation.custom.seo_title'),
|
|
|
|
|
'seo_description' => trans('validation.custom.seo_description'),
|
|
|
|
|
'title' => trans('validation.attributes.title'),
|
|
|
|
|
'content' => trans('validation.attributes.content'),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|