CKeditor + word counter + Image Input + Taggable VUE3 Better Xss Sanitizer Handle Video Youtube + Image Upload + Inline Image from url Better Image Input component with reset, easizer resize Full Responsive BO
80 lines
2.3 KiB
PHP
80 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\News;
|
|
|
|
use App\Enums\PublishedStatus;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Str;
|
|
use Kwaadpepper\Enum\Rules\EnumIsValidRule;
|
|
|
|
/**
|
|
* Unicity for fields is handled by model events
|
|
*/
|
|
class StoreNewsRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return auth('backend')->check();
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function prepareForValidation()
|
|
{
|
|
$this->merge([
|
|
'slug' => Str::slug($this->title),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
'title' => 'required|min:6|max:255',
|
|
'slug' => 'required|max:255',
|
|
'seo_title' => 'required|min:53|max:60',
|
|
'seo_description' => 'required|min:50|max:160',
|
|
'content' => 'required|string|min:15',
|
|
'picture' => 'sometimes|image|dimensions:width=300,height=300|mimes:png,jpg,jpeg,gif',
|
|
'picture_alt' => 'required_with:picture|nullable|string|min:6|max:255',
|
|
'picture_title' => 'required_with:picture|nullable|string|min:6|max:255',
|
|
'published' => ['required', new EnumIsValidRule(PublishedStatus::class)],
|
|
'tags' => 'sometimes|array',
|
|
'tags.*' => 'required|array',
|
|
'tags.*.id' => 'required|numeric|exists:tags,id|distinct',
|
|
'tags.*.name' => 'required|string',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'title' => trans('title'),
|
|
'slug' => trans('title'),
|
|
'seo_title' => trans('title') . ' seo',
|
|
'seo_description' => trans('description') . ' seo',
|
|
'content' => trans('content'),
|
|
'picture' => trans('vignette'),
|
|
'picture_alt' => trans('Texte alternatif de la vignette'),
|
|
'picture_title' => trans('Titre de la vignette'),
|
|
'published' => trans('published'),
|
|
];
|
|
}
|
|
}
|