ldc-domaine-de-lanvaux/app/Http/Requests/StoreGammeRequest.php
Alexis Gousseau 4c39db12d7 Refonte
2022-08-05 09:38:44 +00:00

85 lines
2.3 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;
class StoreGammeRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize(): bool
{
$this->merge([
'slug' => Str::slug($this->title),
'parent_gamme_id' => $this->parent_gamme_id === '0' ? null : $this->parent_gamme_id,
]);
return auth()->check();
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation(): void
{
$tabPictos = config('lists.labelsGammes');
$tabPictos['frais']['status'] = $this->is_activated1 ? true : false;
$tabPictos['mi-cuit']['status'] = $this->is_activated2 ? true : false;
$tabPictos['conserve']['status'] = $this->is_activated3 ? true : false;
$tabPictos['surgele']['status'] = $this->is_activated4 ? true : false;
$tabPictos = json_encode($tabPictos);
$this->merge([
'pictos' => $tabPictos,
]);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [
'parent_gamme_id' => 'sometimes|nullable|exists:gammes,id',
'title' => 'required|string|max:255',
'slug' => 'required|unique:gammes',
'text' => 'required|string|max:500',
'color' => 'sometimes',
'picture1' => 'sometimes|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=370,height=370',
'alt_text_picture1' => 'required|max:255',
'picture2' => 'sometimes|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=1920,height=591',
'alt_text_picture2' => 'required|max:255',
'pictos' => 'sometimes|nullable',
];
}
/**
* Get custom messages for validator errors.
*
* @return array
*/
public function messages(): array
{
return [];
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
'slug' => trans('Nom')
];
}
}