You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.2 KiB
73 lines
2.2 KiB
<?php
|
|
|
|
namespace App\Http\Requests\Admin;
|
|
|
|
use App\Models\Competition;
|
|
use App\Models\FormSchemaDefinition;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class StoreCompetitionRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'slug' => [
|
|
'required',
|
|
'string',
|
|
'max:128',
|
|
'regex:/^(?!.*\s)[\p{L}\p{N}\-_·]+$/u',
|
|
'unique:competitions,slug',
|
|
],
|
|
'name' => ['required', 'string', 'max:200'],
|
|
'description' => ['nullable', 'string'],
|
|
'pledge_content_html' => ['nullable', 'string', 'max:500000'],
|
|
'status' => ['required', 'string', 'max:32', Rule::in(Competition::STATUSES)],
|
|
'published' => ['sometimes', 'boolean'],
|
|
'signup_open_at' => ['nullable', 'date', 'required_with:signup_close_at'],
|
|
'signup_close_at' => ['nullable', 'date', 'after_or_equal:signup_open_at'],
|
|
'form_schema_id' => [
|
|
'nullable',
|
|
'integer',
|
|
Rule::exists('form_schema_definitions', 'id')->where('purpose', FormSchemaDefinition::PURPOSE_SIGNUP),
|
|
],
|
|
'review_form_schema_id' => [
|
|
'nullable',
|
|
'integer',
|
|
Rule::exists('form_schema_definitions', 'id')->where('purpose', FormSchemaDefinition::PURPOSE_REVIEW),
|
|
],
|
|
'branding_json' => ['nullable', 'array'],
|
|
'settings' => ['nullable', 'array'],
|
|
'scoring_rules_json' => ['nullable', 'array'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'slug' => '访问地址',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'slug.regex' => ':attribute 仅可为中文、字母、数字、横线、下划线或中点,且不能含空格。',
|
|
];
|
|
}
|
|
}
|