107 lines
3.9 KiB
PHP
107 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\LocalCommitments;
|
|
|
|
use App\Traits\Requests\HasPicture;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class StoreLocalCommitmentRequest 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('picture1');
|
|
$this->mergePicture('picture2');
|
|
$this->mergePicture('picture3');
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
'title' => 'required|string|between:3,255',
|
|
'text' => 'required|string|min:15',
|
|
'picture1_alt' => 'required|string|between:3,255',
|
|
'picture1_title' => 'required|string|between:3,255',
|
|
'picture2_alt' => 'nullable|required_with:picture2|string|between:3,255',
|
|
'picture2_title' => 'nullable|required_with:picture2|string|between:3,255',
|
|
'picture3_alt' => 'nullable|required_with:picture3|string|between:3,255',
|
|
'picture3_title' => 'nullable|required_with:picture3|string|between:3,255',
|
|
'published' => 'required|boolean',
|
|
];
|
|
|
|
return \array_merge(
|
|
$rules,
|
|
$this->pictureRules('picture1', 587, 429, 587, 429, false),
|
|
$this->pictureRules('picture2', 587, 429, 587, 429, true),
|
|
$this->pictureRules('picture3', 587, 429, 587, 429, true),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'title' => trans('validation.attributes.title'),
|
|
'text' => trans('validation.attributes.text.'),
|
|
'picture1_alt' => trans(':field1 :inter:model', [
|
|
'field1' => trans('validation.custom.attribute_alt'),
|
|
'inter' => trans('validation.custom.of_the.female'),
|
|
'field2' => trans('validation.custom._image')
|
|
]),
|
|
'picture1_title' => trans(':field1 :inter:model', [
|
|
'field1' => trans('validation.custom.attribute_title'),
|
|
'inter' => trans('validation.custom.of_the.female'),
|
|
'field2' => trans('validation.custom._image')
|
|
]),
|
|
'picture2_alt' => trans(':field1 :inter:model', [
|
|
'field1' => trans('validation.custom.attribute_alt'),
|
|
'inter' => trans('validation.custom.of_the.female'),
|
|
'field2' => trans('validation.custom._image')
|
|
]),
|
|
'picture2_title' => trans(':field1 :inter:model', [
|
|
'field1' => trans('validation.custom.attribute_title'),
|
|
'inter' => trans('validation.custom.of_the.female'),
|
|
'field2' => trans('validation.custom._image')
|
|
]),
|
|
'picture3_alt' => trans(':field1 :inter:model', [
|
|
'field1' => trans('validation.custom.attribute_alt'),
|
|
'inter' => trans('validation.custom.of_the.female'),
|
|
'field2' => trans('validation.custom._image')
|
|
]),
|
|
'picture3_title' => trans(':field1 :inter:model', [
|
|
'field1' => trans('validation.custom.attribute_title'),
|
|
'inter' => trans('validation.custom.of_the.female'),
|
|
'field2' => trans('validation.custom._image')
|
|
]),
|
|
'published' => trans('validation.custom.activated'),
|
|
];
|
|
}
|
|
}
|