85 lines
2.8 KiB
PHP
85 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\NewsBreedings;
|
|
|
|
use App\Enums\StaticPageType;
|
|
use App\Models\NewsBreeding;
|
|
use App\Rules\WysiwygLength;
|
|
use App\Traits\Requests\HasPicture;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class StoreNewsBreedingRequest extends FormRequest
|
|
{
|
|
use HasPicture;
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return Gate::check('create', NewsBreeding::class);
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'published' => $this->boolean('published'),
|
|
]);
|
|
$this->mergePicture('picture');
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
'seo_title' => 'required|string|between:45,70',
|
|
'seo_description' => 'required|string|between:50,160',
|
|
'title' => 'required|string|between:3,255',
|
|
'subtitle' => 'required|string|between:3,255',
|
|
'content' => ['required', 'string', new WysiwygLength(15, 15000)],
|
|
'static_page_id' => [
|
|
'required',
|
|
Rule::exists('static_pages', 'id')->whereIn(
|
|
'type',
|
|
array_column(StaticPageType::getBreedingPages(), 'value')
|
|
),
|
|
],
|
|
'picture_alt' => 'required_with:picture|between:3,255',
|
|
'picture_title' => 'required_with:picture|between:3,255',
|
|
'published' => 'required|boolean',
|
|
'publish_at' => 'nullable|date',
|
|
'unpublish_at' => 'nullable|date|after:publish_at',
|
|
];
|
|
|
|
return \array_merge(
|
|
$rules,
|
|
$this->pictureRules('picture', 700, 400, 700, 400),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'title' => trans('validation.attributes.title'),
|
|
'content' => trans('validation.attributes.content'),
|
|
'url' => trans('validation.custom.url'),
|
|
'static_page_id' => trans_choice('validation.custom.static_page_id', 1),
|
|
'picture' => trans('validation.attributes.image'),
|
|
'picture_alt' => trans('validation.custom.attribute_alt'),
|
|
'picture_title' => trans('validation.custom.attribute_title'),
|
|
'published' => trans('validation.attributes.published'),
|
|
'publish_at' => trans('validation.custom.publish_at'),
|
|
'unpublish_at' => trans('validation.custom.unpublish_at'),
|
|
];
|
|
}
|
|
}
|