52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\Admin;
|
|
|
|
use App\Models\PreregistrationPage;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class UpdateMailwizzConfigRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
$page = $this->route('page');
|
|
if (! $page instanceof PreregistrationPage) {
|
|
return false;
|
|
}
|
|
|
|
return $this->user()?->can('update', $page) ?? false;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, array<int, ValidationRule|string>>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
/** @var PreregistrationPage $page */
|
|
$page = $this->route('page');
|
|
|
|
return [
|
|
'api_key' => [
|
|
Rule::requiredIf(fn (): bool => $page->mailwizzConfig === null),
|
|
'nullable',
|
|
'string',
|
|
'max:512',
|
|
],
|
|
'list_uid' => ['required', 'string', 'max:255'],
|
|
'list_name' => ['nullable', 'string', 'max:255'],
|
|
'field_email' => ['required', 'string', 'max:255'],
|
|
'field_first_name' => ['required', 'string', 'max:255'],
|
|
'field_last_name' => ['required', 'string', 'max:255'],
|
|
'field_phone' => $page->phone_enabled
|
|
? ['required', 'string', 'max:255']
|
|
: ['nullable', 'string', 'max:255'],
|
|
'tag_field' => ['required', 'string', 'max:255'],
|
|
'tag_value' => ['required', 'string', 'max:255'],
|
|
];
|
|
}
|
|
}
|