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.
64 lines
1.6 KiB
64 lines
1.6 KiB
|
1 month ago
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Requests\Admin;
|
||
|
|
|
||
|
|
use App\Models\CompetitionTrack;
|
||
|
|
use Illuminate\Foundation\Http\FormRequest;
|
||
|
|
use Illuminate\Validation\Rule;
|
||
|
|
|
||
|
|
class UpdateCompetitionTrackRequest extends FormRequest
|
||
|
|
{
|
||
|
|
public function authorize(): bool
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return array<string, mixed>
|
||
|
|
*/
|
||
|
|
public function rules(): array
|
||
|
|
{
|
||
|
|
$competition = $this->route('competition');
|
||
|
|
$track = $this->route('track');
|
||
|
|
assert($track instanceof CompetitionTrack);
|
||
|
|
|
||
|
|
$competitionId = is_object($competition) ? $competition->id : null;
|
||
|
|
|
||
|
|
return [
|
||
|
|
'track_code' => [
|
||
|
|
'sometimes',
|
||
|
|
'string',
|
||
|
|
'max:64',
|
||
|
|
'regex:/^(?!.*\s)[\p{L}\p{N}\-_·]+$/u',
|
||
|
|
Rule::unique('competition_tracks', 'track_code')
|
||
|
|
->where('competition_id', $competitionId)
|
||
|
|
->ignore($track->id),
|
||
|
|
],
|
||
|
|
'title' => ['sometimes', 'string', 'max:128'],
|
||
|
|
'description' => ['sometimes', '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 仅可为中文、字母、数字、横线、下划线或中点,且不能含空格。',
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|