80 lines
2.7 KiB
PHP
80 lines
2.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Requests;
|
||
|
|
|
||
|
|
use App\Enums\InputType;
|
||
|
|
use App\Models\BreedingPage;
|
||
|
|
use Illuminate\Support\Str;
|
||
|
|
|
||
|
|
class StoreBreedingPageRequest extends StoreMiniAcfRequest
|
||
|
|
{
|
||
|
|
|
||
|
|
protected $model = BreedingPage::class;
|
||
|
|
|
||
|
|
public function authorize()
|
||
|
|
{
|
||
|
|
if (
|
||
|
|
is_null(request()->breeding_page_type) or
|
||
|
|
BreedingPage::where('type', request()->breeding_page_type)->count() >= 10
|
||
|
|
) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
$this->merge([
|
||
|
|
'status' => $this->status ? true : false
|
||
|
|
]);
|
||
|
|
return auth()->check();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the validation rules that apply to the request.
|
||
|
|
*
|
||
|
|
* @return array
|
||
|
|
*/
|
||
|
|
public function rules()
|
||
|
|
{
|
||
|
|
$rules = [
|
||
|
|
'title' => [
|
||
|
|
'required', 'string', 'min:7', 'max:255',
|
||
|
|
function ($attribute, $value, $fail) {
|
||
|
|
if (BreedingPage::where('slug', Str::slug($value))->exists()) {
|
||
|
|
$fail(trans('La valeur du champ :attribute est déjà utilisé.', [
|
||
|
|
'attribute' => $this->attributes()[$attribute]
|
||
|
|
]));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
],
|
||
|
|
'seo_title' => 'required|string|min:20|max:60',
|
||
|
|
'seo_description' => 'required|string|min:130|max:160',
|
||
|
|
'headerContent' => 'required|string|min:10',
|
||
|
|
'subtitle' => 'required|string|min:5',
|
||
|
|
'subtitleContent' => 'required|string|min:10',
|
||
|
|
'media_type' => 'required|in:' . implode(',', [InputType::image()->value, InputType::videoVimeo()->value]),
|
||
|
|
// phpcs:ignore Generic.Files.LineLength.TooLong
|
||
|
|
'picture' => 'required_if:media_type,' . InputType::image()->value . '|image|mimes:jpeg,png,jpg|max:2048|dimensions:height=615,width=575',
|
||
|
|
'picture_alt' => 'required_if:media_type,' . InputType::image()->value . '|string|min:5',
|
||
|
|
// phpcs:ignore Generic.Files.LineLength.TooLong
|
||
|
|
'video' => 'required_if:media_type,' . InputType::videoVimeo()->value . '|url|regex:/^https:\/\/vimeo\.com\/[0-9]{8,10}$/',
|
||
|
|
'status' => 'required|boolean'
|
||
|
|
];
|
||
|
|
return array_merge(
|
||
|
|
$rules,
|
||
|
|
$this->generatedRules
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function attributes()
|
||
|
|
{
|
||
|
|
return \array_merge(
|
||
|
|
[
|
||
|
|
'menutitle' => \trans('Titre menu'),
|
||
|
|
'title' => \trans('Titre'),
|
||
|
|
'metaTitle' => \trans('Titre'),
|
||
|
|
'metaDescription' => \trans('Description meta'),
|
||
|
|
'headerContent' => \trans('Contenu entête'),
|
||
|
|
'status' => \trans('Publié')
|
||
|
|
],
|
||
|
|
parent::attributes()
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|