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.

58 lines
1.4 KiB

1 month ago
<?php
namespace App\Http\Requests\Admin;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class StoreCompetitionTrackRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
$competition = $this->route('competition');
$competitionId = is_object($competition) ? $competition->id : null;
return [
'track_code' => [
'required',
'string',
'max:64',
'regex:/^(?!.*\s)[\p{L}\p{N}\-_·]+$/u',
Rule::unique('competition_tracks', 'track_code')->where('competition_id', $competitionId),
],
'title' => ['required', 'string', 'max:128'],
'description' => ['nullable', 'string', 'max:512'],
'sort' => ['sometimes', 'integer'],
'is_enabled' => ['sometimes', 'boolean'],
];
}
/**
* @return array<string, string>
*/
public function attributes(): array
{
return [
'track_code' => '赛道编码',
];
}
/**
* @return array<string, string>
*/
public function messages(): array
{
return [
'track_code.regex' => ':attribute 仅可为中文、字母、数字、横线、下划线或中点,且不能含空格。',
];
}
}