66 lines
1.7 KiB
PHP
66 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Enums\RangeColor;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Str;
|
|
use Kwaadpepper\Enum\Rules\EnumIsValidRule;
|
|
|
|
class StoreRange extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize()
|
|
{
|
|
$this->merge([
|
|
'status' => $this->status ? 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|max:50',
|
|
'slug' => 'required|unique:ranges,slug',
|
|
'description' => 'required|max:255',
|
|
'picture' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=640,height=564',
|
|
'picture_r' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=1366,height=563',
|
|
'color' => [
|
|
'required',
|
|
'max:20',
|
|
new EnumIsValidRule(RangeColor::class)
|
|
]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes()
|
|
{
|
|
return [
|
|
'name' => 'Nom',
|
|
'slug' => 'Nom',
|
|
'description' => 'Description',
|
|
'picture' => 'Image',
|
|
'picture_r' => 'Image bannière',
|
|
'color' => 'Couleur',
|
|
'status' => 'Publié',
|
|
'flagship_product' => 'Produit phare',
|
|
'subranges' => 'Sous gammes'
|
|
];
|
|
}
|
|
}
|