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.

56 lines
1.8 KiB

<?php
namespace App\Http\Requests\Admin;
use App\Models\SignupChannel;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateSignupChannelRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'channel_code' => ['prohibited'],
'competition_id' => ['prohibited'],
'channel_name' => ['sometimes', 'string', 'max:200'],
'status' => ['sometimes', Rule::in(SignupChannel::STATUSES)],
'shared_secret' => ['sometimes', 'string', 'max:255'],
'entry_encryption_enabled' => ['sometimes', 'boolean'],
'success_callback_url' => ['sometimes', 'nullable', 'url:http,https', 'max:2048'],
'success_callback_type' => ['sometimes', Rule::in(SignupChannel::CALLBACK_TYPES)],
'mini_program_callback_path' => [
'nullable',
'string',
'max:1024',
'regex:/^\/(?!\/)[^#]*$/',
Rule::requiredIf(fn (): bool => $this->resolvedCallbackType() === SignupChannel::CALLBACK_TYPE_MINI_PROGRAM),
],
'mini_program_callback_method' => ['sometimes', Rule::in(SignupChannel::MINI_PROGRAM_METHODS)],
'remark' => ['sometimes', 'nullable', 'string'],
];
}
private function resolvedCallbackType(): string
{
$requestedType = $this->input('success_callback_type');
if (is_string($requestedType) && $requestedType !== '') {
return $requestedType;
}
$channel = $this->route('signup_channel');
return $channel instanceof SignupChannel
? (string) $channel->success_callback_type
: SignupChannel::CALLBACK_TYPE_WEB;
}
}