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.
78 lines
2.4 KiB
78 lines
2.4 KiB
<?php
|
|
|
|
namespace App\Http\Requests\Admin;
|
|
|
|
use App\Models\AudienceSession;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class UpdateAudienceSessionRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$competition = $this->route('competition');
|
|
$session = $this->route('audience_session');
|
|
assert($session instanceof AudienceSession);
|
|
|
|
$competitionId = is_object($competition) ? $competition->id : null;
|
|
|
|
return [
|
|
'code' => [
|
|
'sometimes',
|
|
'string',
|
|
'max:64',
|
|
'regex:/^(?!.*\s)[A-Za-z0-9\-_]+$/',
|
|
Rule::unique('audience_sessions', 'code')
|
|
->where('competition_id', $competitionId)
|
|
->ignore($session->id),
|
|
],
|
|
'name' => ['sometimes', 'string', 'max:128'],
|
|
'name_en' => ['sometimes', 'nullable', 'string', 'max:128'],
|
|
'event_date_text' => ['sometimes', 'string', 'max:128'],
|
|
'event_date_text_en' => ['sometimes', 'nullable', 'string', 'max:128'],
|
|
'address' => ['sometimes', 'string', 'max:255'],
|
|
'address_en' => ['sometimes', 'nullable', 'string', 'max:255'],
|
|
'capacity' => ['sometimes', 'integer', 'min:1', 'max:100000'],
|
|
'signup_start_at' => ['sometimes', 'date'],
|
|
'signup_end_at' => ['sometimes', 'date'],
|
|
'is_final' => ['sometimes', 'boolean'],
|
|
'sort' => ['sometimes', 'integer'],
|
|
'enabled' => ['sometimes', 'boolean'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'code' => '场次编码',
|
|
'name' => '场次名称',
|
|
'event_date_text' => '活动时间',
|
|
'address' => '活动地点',
|
|
'capacity' => '容量',
|
|
'signup_start_at' => '报名开始时间',
|
|
'signup_end_at' => '报名结束时间',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'code.regex' => ':attribute 仅可为字母、数字、横线或下划线,且不能含空格。',
|
|
];
|
|
}
|
|
}
|