ldc-showroom-bo/app/Http/Requests/Bo/Ranges/StoreRangeRequest.php
2024-01-30 17:09:20 +01:00

77 lines
2 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;
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([
'shelf' => $this->boolean('shelf'),
'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|color_hex',
'width' => 'required|numeric|min:1|max:2',
'shelf' => 'present|boolean',
'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'),
'shelf' => \trans('validation.custom.shelf'),
];
}
}