2022-08-05 09:38:44 +00:00
|
|
|
<?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
|
|
|
|
|
{
|
|
|
|
|
return auth()->check();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepare the data for validation.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function prepareForValidation(): void
|
|
|
|
|
{
|
|
|
|
|
$this->merge([
|
2022-11-17 16:08:32 +01:00
|
|
|
'slug' => Str::slug($this->title),
|
|
|
|
|
'parent_gamme_id' => $this->parent_gamme_id === '0' ? null : $this->parent_gamme_id,
|
2022-08-05 09:38:44 +00:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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',
|
|
|
|
|
'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',
|
2022-11-17 16:08:32 +01:00
|
|
|
'picture3' => 'sometimes|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=84,height=84',
|
2023-01-09 15:16:02 +01:00
|
|
|
'alt_text_picture3' => 'sometimes|max:255',
|
2022-11-17 16:08:32 +01:00
|
|
|
'category' => 'sometimes|nullable',
|
2022-08-05 09:38:44 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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')
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|