86 lines
2.2 KiB
PHP
86 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\Ranges;
|
|
|
|
use App\Enums\Width;
|
|
use App\Models\Range;
|
|
use App\Traits\Requests\HasPicture;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use App\Rules\Hex;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
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', Rule::enum(Width::class)],
|
|
'status' => 'present|boolean',
|
|
];
|
|
|
|
$widthEnum = Width::make($this->input('width'));
|
|
return \array_merge(
|
|
$rules,
|
|
$this->pictureRules(
|
|
'picture',
|
|
$widthEnum->dimValidation()['width'],
|
|
$widthEnum->dimValidation()['height'],
|
|
$widthEnum->dimValidation()['width'],
|
|
$widthEnum->dimValidation()['height'],
|
|
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'),
|
|
];
|
|
}
|
|
}
|