82 lines
3.8 KiB
PHP
82 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace Modules\Countries\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
use Modules\Countries\Support\Iso3166;
|
|
|
|
class StoreCountryRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Authorize country reference-data administration.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return (bool) $this->user()?->isMpbaPlatformAdmin();
|
|
}
|
|
|
|
/**
|
|
* Normalise ISO code inputs before validation.
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'alpha2' => strtoupper(trim((string) $this->input('alpha2'))),
|
|
'alpha3' => strtoupper(trim((string) $this->input('alpha3'))),
|
|
'numeric' => str_pad(trim((string) $this->input('numeric')), 3, '0', STR_PAD_LEFT),
|
|
'currency_code' => $this->filled('currency_code') ? strtoupper(trim((string) $this->input('currency_code'))) : null,
|
|
'ioc_code' => $this->filled('ioc_code') ? strtoupper(trim((string) $this->input('ioc_code'))) : null,
|
|
'fifa_code' => $this->filled('fifa_code') ? strtoupper(trim((string) $this->input('fifa_code'))) : null,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'alpha2' => ['required', 'string', 'size:2', 'uppercase', 'unique:countries,alpha2'],
|
|
'alpha3' => ['required', 'string', 'size:3', 'uppercase', 'unique:countries,alpha3'],
|
|
'numeric' => ['required', 'string', 'size:3', 'unique:countries,numeric'],
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'official_name' => ['nullable', 'string', 'max:255'],
|
|
'common_name' => ['nullable', 'string', 'max:255'],
|
|
'display_name' => ['nullable', 'string', 'max:255'],
|
|
'native_name' => ['nullable', 'string', 'max:255'],
|
|
'capital' => ['nullable', 'string', 'max:255'],
|
|
'flag_emoji' => ['nullable', 'string', 'max:16'],
|
|
'calling_code' => ['nullable', 'string', 'max:16'],
|
|
'tld' => ['nullable', 'string', 'max:16'],
|
|
'currency_code' => ['nullable', 'string', 'size:3', 'uppercase'],
|
|
'currency_name' => ['nullable', 'string', 'max:255'],
|
|
'currency_symbol' => ['nullable', 'string', 'max:16'],
|
|
'languages' => ['nullable', 'json'],
|
|
'timezones' => ['nullable', 'json'],
|
|
'latitude' => ['nullable', 'numeric', 'between:-90,90'],
|
|
'longitude' => ['nullable', 'numeric', 'between:-180,180'],
|
|
'flag_svg_url' => ['nullable', 'url', 'max:255'],
|
|
'flag_png_url' => ['nullable', 'url', 'max:255'],
|
|
'ioc_code' => ['nullable', 'string', 'max:8'],
|
|
'fifa_code' => ['nullable', 'string', 'max:8'],
|
|
'postal_code_format' => ['nullable', 'string', 'max:255'],
|
|
'address_format' => ['nullable', 'string', 'max:5000'],
|
|
'is_active' => ['required', 'boolean'],
|
|
'iso_status' => ['required', 'string', Rule::in(Iso3166::statuses())],
|
|
'independent' => ['nullable', 'boolean'],
|
|
'sovereignty_status' => ['nullable', 'string', 'max:64'],
|
|
'un_member' => ['nullable', 'boolean'],
|
|
'continent' => ['nullable', 'string', 'max:64'],
|
|
'region' => ['nullable', 'string', 'max:100'],
|
|
'subregion' => ['nullable', 'string', 'max:100'],
|
|
'intermediate_region' => ['nullable', 'string', 'max:255'],
|
|
'sort_order' => ['nullable', 'integer', 'min:0', 'max:999999'],
|
|
'source' => ['nullable', 'string', 'max:255'],
|
|
'source_version' => ['nullable', 'string', 'max:255'],
|
|
'last_synced_at' => ['nullable', 'date'],
|
|
'metadata' => ['nullable', 'json'],
|
|
];
|
|
}
|
|
}
|