78 lines
2.4 KiB
PHP
78 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\NewsBreedings;
|
|
|
|
use App\Models\NewsBreeding;
|
|
use App\Traits\Requests\HasPicture;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
class StoreNewsBreedingRequest extends FormRequest
|
|
{
|
|
use HasPicture;
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return Gate::check('create', NewsBreeding::class);
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->mergePicture('picture');
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
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|between:3,255',
|
|
'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.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'title' => trans('validation.attributes.title'),
|
|
'content' => trans('validation.attributes.content'),
|
|
'url' => trans('validation.custom.url'),
|
|
'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'),
|
|
];
|
|
}
|
|
}
|