86 lines
2.6 KiB
PHP
86 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\Breeders;
|
|
|
|
use App\Traits\Requests\HasPicture;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* Unicity for fields is handled by model events
|
|
*/
|
|
class StoreBreederRequest extends FormRequest
|
|
{
|
|
use HasPicture;
|
|
|
|
/**
|
|
* 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->firstname . " " . $this->lastname),
|
|
'status' => $this->status ? true : false,
|
|
]);
|
|
$this->mergePicture('banner');
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
$regex = '/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/';
|
|
return \array_merge(
|
|
[
|
|
'firstname' => 'required|string|min:1|max:255',
|
|
'lastname' => 'required|string|min:1|max:255',
|
|
'slug' => 'required|max:255',
|
|
'biography' => 'required|string|min:15',
|
|
'banner_alt' => 'required_with:banner|nullable|string|min:6|max:255',
|
|
'banner_title' => 'required_with:banner|nullable|string|min:6|max:255',
|
|
'title' => 'required|string|min:6|max:255',
|
|
'testimony' => 'required|string|min:15',
|
|
'video' => 'required|string|min:6|max:255|regex:' . $regex,
|
|
'status' => 'required|boolean',
|
|
],
|
|
$this->pictureRules('banner', 1919, 423, 1919, 423),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'firstname' => trans('Prénom de l\éleveur'),
|
|
'lastname' => trans('Nom de l\éleveur'),
|
|
'slug' => trans('Slug'),
|
|
'biography' => trans('Description de la recette'),
|
|
'banner' => trans('Bannière'),
|
|
'banner_alt' => trans('Texte alternatif de la bannière'),
|
|
'banner_title' => trans('Titre de la bannière'),
|
|
'title' => trans('Titre du témoignage'),
|
|
'testimony' => trans('Témoignage de l\'éleveur'),
|
|
'video' => trans('Vidéo de la recette de l\'éleveur'),
|
|
'status' => trans('Publié ?')
|
|
];
|
|
}
|
|
}
|