76 lines
2.1 KiB
PHP
76 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\StaticPages;
|
|
|
|
use App\Enums\StaticPageType;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
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 auth('backend')->check();
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'content' => $this->input('content') ? Str::of($this->input('content'))->value() : null
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
'seo_title' => 'nullable',
|
|
'seo_description' => 'nullable',
|
|
'title' => 'required|min:3|max:255',
|
|
'content' => 'nullable',
|
|
'data' => 'present|array',
|
|
'data.*' => 'required|array',
|
|
];
|
|
|
|
$staticPageModel = request()->route()->parameter('static_page');
|
|
if (
|
|
!$staticPageModel->type->equals(StaticPageType::banner_section)
|
|
) {
|
|
$rules = \array_merge(
|
|
$rules,
|
|
[
|
|
'seo_title' => 'required|min:45|max:70',
|
|
'seo_description' => 'required|min:50|max:160',
|
|
],
|
|
);
|
|
}
|
|
|
|
if (
|
|
!$staticPageModel->type->equals(StaticPageType::homepage) &&
|
|
!$staticPageModel->type->equals(StaticPageType::our_products) &&
|
|
!$staticPageModel->type->equals(StaticPageType::our_commitments) &&
|
|
!$staticPageModel->type->equals(StaticPageType::banner_section)
|
|
) {
|
|
$rules = \array_merge(
|
|
$rules,
|
|
['content' => ['present']],
|
|
);
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
}
|