62 lines
2.1 KiB
PHP
62 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Back\PageConfigs;
|
|
|
|
use App\Enums\DynamicFieldTypes;
|
|
use App\Models\PageConfig;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Validation\Rules\Enum;
|
|
|
|
class StorePageConfigRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return Gate::check('create', PageConfig::class);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'label' => 'required|string|between:3,255',
|
|
'view' => 'sometimes|nullable|string|between:3,255',
|
|
'config' => 'required|array|min:1',
|
|
'config.*' => 'required|array|size:5',
|
|
'config.*.key' => 'required|string|between:3,255|regex:/^[a-z0-9]+(?:[-_][a-z0-9]+)*$/',
|
|
'config.*.order' => 'required|numeric|min:1',
|
|
'config.*.type' => ['required', new Enum(DynamicFieldTypes::class)],
|
|
'config.*.label' => 'required|string|between:3,255',
|
|
'config.*.validation' => 'required|string|between:3,255',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'label' => trans('validation.custom.label'),
|
|
'view' => trans('validation.custom.view'),
|
|
'config' => trans('validation.custom.config'),
|
|
'config.*' => trans('validation.custom.config'),
|
|
'config.*.key' => trans('validation.custom.key'),
|
|
'config.*.order' => trans('validation.custom.order'),
|
|
'config.*.type' => trans('validation.custom.type'),
|
|
'config.*.label' => trans('validation.custom.label'),
|
|
'config.*.validation' => trans('validation.custom.validation'),
|
|
];
|
|
}
|
|
}
|