ldc-legaulois/app/Http/Requests/StoreSubRange.php
Jérémy Munsch 5be40abc2e
add back_link_display to subranges
add subrange infos on product index
2021-09-24 16:08:47 +02:00

66 lines
1.9 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;
class StoreSubRange extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
$this->merge([
'back_link_display' => $this->back_link_display ? true : false,
'slug' => Str::slug($this->name)
]);
return auth()->check();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required|string|min:2|max:28',
'slug' => 'required|unique:ranges,slug',
'picture' => 'sometimes|image|max:2048|mimes:png,jpg,jpeg|dimensions:height=170,width=170',
'picture_alt' => 'required_with:picture|string|min:10|max:255',
'title' => 'required|string|min:10|max:255',
'subtitle' => 'required|string|min:10|max:255',
'content' => 'required|string|min:20',
'back_link_display' => 'required|boolean',
'back_link_url' => 'exclude_if:back_link_display,false|required|url',
'back_link_text' => 'exclude_if:back_link_display,false|required|string|min:2|max:20',
];
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes()
{
return [
'name' => 'Nom',
'slug' => 'Nom',
'title' => 'Titre',
'description' => 'Description',
'picture' => 'Image',
'picture_alt' => 'Texte alternatif d\'image',
'subtitle' => 'Sous titre',
'content' => 'Contenu',
'back_link_url' => 'Url du lien',
'back_link_text' => 'Texte du lien',
'back_link_display' => 'Afficher le lien ?'
];
}
}