88 lines
3.3 KiB
PHP
88 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\News;
|
|
|
|
use App\Models\News;
|
|
use App\Rules\WysiwygLength;
|
|
use App\Traits\Requests\HasPicture;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
class StoreNewsRequest extends FormRequest
|
|
{
|
|
use HasPicture;
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return Gate::check('create', News::class);
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->mergePicture('picture');
|
|
$this->mergePicture('thumbnail');
|
|
$this->merge([
|
|
'published' => $this->boolean('published'),
|
|
'highlight' => $this->boolean('highlight'),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 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' => 'sometimes|nullable|string|between:3,255',
|
|
'picture_alt' => 'required|string|between:3,255',
|
|
'picture_title' => 'required|string|between:3,255',
|
|
'thumbnail_alt' => 'required|string|between:3,255',
|
|
'thumbnail_title' => 'required|string|between:3,255',
|
|
'news_category_id' => 'required|integer',
|
|
'content' => ['required', 'string', new WysiwygLength()],
|
|
'highlight' => 'required|boolean',
|
|
'published' => 'required|boolean',
|
|
'publish_at' => 'sometimes|nullable|date',
|
|
'unpublish_at' => 'sometimes|nullable|date|after:publish_at',
|
|
];
|
|
|
|
return \array_merge(
|
|
$rules,
|
|
$this->pictureRules('picture', 700, 400, 700, 400),
|
|
$this->pictureRules('thumbnail', 360, 250, 360, 250),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'seo_title' => trans('validation.attributes.title'),
|
|
'seo_description' => trans('validation.attributes.title'),
|
|
'title' => trans('validation.attributes.title'),
|
|
'subtitle' => trans('validation.attributes.subtitle'),
|
|
'content' => trans('validation.attributes.content'),
|
|
'news_category_id' => trans('validation.custom.category'),
|
|
'picture' => trans('validation.attributes.image'),
|
|
'picture_alt' => trans('validation.custom.attribute_alt'),
|
|
'picture_title' => trans('validation.custom.attribute_title'),
|
|
'thumbnail_alt' => trans('validation.custom.attribute_alt'),
|
|
'thumbnail_title' => trans('validation.custom.attribute_title'),
|
|
'published' => trans('validation.attributes.published'),
|
|
'highlight' => trans('validation.attributes.highlight'),
|
|
'publish_at' => trans('validation.custom.publish_at'),
|
|
'unpublish_at' => trans('validation.custom.unpublish_at'),
|
|
];
|
|
}
|
|
}
|