73 lines
2 KiB
PHP
73 lines
2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Str;
|
|
|
|
class StoreProductRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function authorize()
|
|
{
|
|
$this->merge([
|
|
'slug' => Str::slug($this->name),
|
|
'gamme_id' => $this->gamme_id === '0' ? null : $this->gamme_id,
|
|
'sous_gamme_id' => $this->sous_gamme_id === '0' ? null : $this->sous_gamme_id,
|
|
'is_published' => $this->is_published ? true : false,
|
|
'is_on_top' => $this->is_on_top ? true : false,
|
|
'is_food_service' => $this->is_food_service ? true : false,
|
|
]);
|
|
|
|
return auth()->check();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
'gamme_id' => 'required|exists:gammes,id',
|
|
'sous_gamme_id' => 'sometimes|nullable|exists:gammes,id',
|
|
'name' => 'required|max:255',
|
|
'slug' => 'required|unique:products',
|
|
'description' => 'required|min:20',
|
|
'picture' => 'required|image|mimes:png|max:1024|dimensions:width=509,height=509',
|
|
'alt_text_picture' => 'required|max:255',
|
|
'is_published' => 'nullable|boolean',
|
|
'is_on_top' => 'nullable|boolean',
|
|
'is_food_service' => 'nullable|boolean',
|
|
// 'seo_title' => 'required|max:255',
|
|
// 'seo_description' => 'required|max:255',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom messages for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function messages()
|
|
{
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes()
|
|
{
|
|
return [
|
|
'slug' => trans('libellé')
|
|
];
|
|
}
|
|
}
|