90 lines
3 KiB
PHP
90 lines
3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\News;
|
|
|
|
use App\Traits\Requests\HasPicture;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class StoreNewsRequest extends FormRequest
|
|
{
|
|
use HasPicture;
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
protected function prepareForValidation()
|
|
{
|
|
$this->merge([
|
|
'published' => $this->published ? true : false
|
|
]);
|
|
$this->mergePicture('picture');
|
|
$this->mergePicture('thumbnail');
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
'seo_title' => 'required|between:45,70',
|
|
'seo_description' => 'required|between:50,160',
|
|
'title' => 'required|string|between:3,100',
|
|
'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',
|
|
'introduction' => 'required|string|min:15',
|
|
'content' => 'nullable|string|min:15',
|
|
'linkedin_url' => 'nullable|url',
|
|
'published' => 'required|boolean',
|
|
'publish_at' => 'nullable|date',
|
|
'unpublish_at' => 'nullable|date|after:publish_at',
|
|
|
|
];
|
|
return \array_merge(
|
|
$rules,
|
|
// FIXME: Mettre à jour les tailles.
|
|
$this->pictureRules('picture', 100, 100, 100, 100, false),
|
|
$this->pictureRules('thumbnail', 100, 100, 100, 100, false),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'seo_title' => trans('validation.custom.seo_title'),
|
|
'seo_description' => trans('validation.custom.seo_description'),
|
|
'title' => trans('validation.attributes.title'),
|
|
'introduction' => trans('validation.attributes.content'),
|
|
'content' => trans('validation.attributes.content'),
|
|
'linkedin_url' => trans('validation.attributes.content'),
|
|
'picture_alt' => trans('validation.custom.picture_alt'),
|
|
'picture_title' => trans('validation.custom.picture_title'),
|
|
'thumbnail_alt' => trans('validation.custom.thumbnail_alt'),
|
|
'thumbnail_title' => trans('validation.custom.thumbnail_title'),
|
|
'published' => trans('validation.custom.activated'),
|
|
'publish_at' => trans('validation.custom.publish_at'),
|
|
'unpublish_at' => trans('validation.custom.unpublish_at'),
|
|
];
|
|
}
|
|
}
|