80 lines
2.8 KiB
PHP
80 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Back\News;
|
|
|
|
use App\Enums\News\NewsCategoryEnum;
|
|
use App\Enums\News\NewsStatusEnum;
|
|
use App\Models\News;
|
|
use App\Traits\Requests\HasInertiaPicture;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Validation\Rules\Enum;
|
|
|
|
class StoreNewsRequest extends FormRequest
|
|
{
|
|
use HasInertiaPicture;
|
|
/**
|
|
* 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.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->mergeInertiaPicture();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'titleSeo' => 'nullable|string|max:60',
|
|
'descriptionSeo' => 'nullable|string|max:255',
|
|
'title' => 'required|string|max:255',
|
|
'slug' => 'required|string|max:255',
|
|
'content' => 'required|string',
|
|
'status' => ['required', new Enum(NewsStatusEnum::class)],
|
|
'picture' => $this->pictureRules("nullable|file|mimes:jpg,jpeg,png|max:5120|dimensions:width=525,height=295"),
|
|
'picture_alt' => 'nullable|string|max:60',
|
|
'picture_title' => 'nullable|string|max:60',
|
|
'categories' => 'nullable|array',
|
|
'categories.*' => ['integer', new Enum(NewsCategoryEnum::class)],
|
|
'published_at' => 'nullable|date',
|
|
'unpublished_at' => 'nullable|date|after:published_at',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'title' => trans('validation.attributes.title'),
|
|
'slug' => trans('validation.custom.slug'),
|
|
'status' => trans('validation.custom.status'),
|
|
'titleSeo' => trans('validation.custom.titleSeo'),
|
|
'descriptionSeo' => trans('validation.custom.descriptionSeo'),
|
|
'categories' => trans('validation.custom.categories'),
|
|
'content' => trans('validation.attributes.content'),
|
|
'picture' => trans('validation.attributes.image'),
|
|
'picture_alt' => trans('validation.custom.attribute_alt'),
|
|
'picture_title' => trans('validation.custom.attribute_title'),
|
|
'published_at' => trans('validation.custom.published_at'),
|
|
'unpublished_at' => trans('validation.custom.unpublished_at'),
|
|
];
|
|
}
|
|
}
|