ldc-domaine-de-lanvaux/app/Http/Requests/StoreGammeRequest.php

76 lines
1.9 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
{
return auth()->check();
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation(): void
{
$this->merge([
'slug' => Str::slug($this->title),
'parent_gamme_id' => $this->parent_gamme_id === '0' ? null : $this->parent_gamme_id,
]);
}
/**
* 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',
'picture3' => 'sometimes|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=84,height=84',
'alt_text_picture3' => 'sometimes|max:255',
'category' => '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')
];
}
}