70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\Fonts;
|
|
|
|
use App\Models\Font;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
class StoreFontRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return Gate::allows('create', Font::class);
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function prepareForValidation()
|
|
{
|
|
$this->merge([
|
|
'font_name' => $this->input('font_name'),
|
|
'font' => $this->input('font')
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'font_name' => [
|
|
'present', 'required_without:font', 'nullable',
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
|
function (string $attribute, $value, callable $fail) {
|
|
$font = $this->input('font');
|
|
if (is_null($font) and !in_array($value, Font::DEFAULT_FONTS)) {
|
|
$fail(trans('validation.in_array', [
|
|
'other' => implode(',', Font::DEFAULT_FONTS)
|
|
]));
|
|
}
|
|
}
|
|
],
|
|
'font' => 'present|nullable'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'font_name' => trans('validation.attributes.name'),
|
|
'font' => trans('validation.custom.font'),
|
|
];
|
|
}
|
|
}
|