ldc-showroom-bo/app/Http/Requests/Bo/Ranges/StoreRangeRequest.php

75 lines
1.9 KiB
PHP

<?php
namespace App\Http\Requests\Bo\Ranges;
use App\Models\Range;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
use App\Rules\Hex;
class StoreRangeRequest extends FormRequest
{
use HasPicture;
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize(): bool
{
return Gate::allows('create', Range::class);
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation()
{
$this->mergePicture('picture');
$this->merge([
'status' => $this->boolean('status')
]);
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
*/
public function rules(): array
{
$rules = [
'name' => 'required|min:2|max:90',
'brand_id' => 'required|exists:brands,id',
'font_id' => 'required|exists:fonts,id',
'color' => ['required', new Hex()],
'width' => 'required|numeric|min:1|max:2',
'status' => 'present|boolean',
];
return \array_merge(
$rules,
$this->pictureRules('picture', 600, 500, 1300, 500, false)
);
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
'brand_id' => \trans_choice('models.classes.brand', 1),
'font_id' => \trans_choice('models.classes.font', 1),
'color' => \trans('validation.custom.color'),
'width' => \trans('validation.custom.width'),
'status' => \trans('validation.custom.status'),
];
}
}