77 lines
2.7 KiB
PHP
Executable File
77 lines
2.7 KiB
PHP
Executable File
<?php
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Route;
|
|
use Modules\Platform\app\Http\Controllers\PlatformDashboardController;
|
|
|
|
Route::get('/', function () {
|
|
return auth()->check()
|
|
? redirect()->route('dashboard')
|
|
: redirect()->route('login');
|
|
})->name('home');
|
|
|
|
Route::get('/dashboard', PlatformDashboardController::class)
|
|
->middleware(['auth', 'verified', 'company.licensed'])
|
|
->name('dashboard');
|
|
|
|
require __DIR__ . '/settings.php';
|
|
|
|
Route::get('/api/countries/resolve/{code}', function (string $code) {
|
|
$normalised = strtoupper(trim($code));
|
|
|
|
$country = DB::table('countries')
|
|
->whereRaw('UPPER(alpha2) = ?', [$normalised])
|
|
->orWhereRaw('UPPER(alpha3) = ?', [$normalised])
|
|
->orWhere('numeric', $normalised)
|
|
->first();
|
|
|
|
abort_if($country === null, 404);
|
|
|
|
return response()->json([
|
|
'data' => [
|
|
'id' => $country->id ?? null,
|
|
'name' => $country->name ?? null,
|
|
'official_name' => $country->official_name ?? null,
|
|
'common_name' => $country->common_name ?? null,
|
|
'display_name' => $country->display_name ?? null,
|
|
'alpha2' => $country->alpha2 ?? null,
|
|
'alpha3' => $country->alpha3 ?? null,
|
|
'numeric' => $country->numeric ?? null,
|
|
'region' => $country->region ?? null,
|
|
'subregion' => $country->subregion ?? null,
|
|
'flag_emoji' => $country->flag_emoji ?? null,
|
|
'is_active' => (bool) ($country->is_active ?? true),
|
|
],
|
|
]);
|
|
})->name('countries.api.resolve.compat');
|
|
|
|
Route::get('/api/countries/{code}/subdivisions', function (string $code) {
|
|
$normalised = strtoupper(trim($code));
|
|
|
|
$country = DB::table('countries')
|
|
->whereRaw('UPPER(alpha2) = ?', [$normalised])
|
|
->orWhereRaw('UPPER(alpha3) = ?', [$normalised])
|
|
->orWhere('numeric', $normalised)
|
|
->first();
|
|
|
|
abort_if($country === null, 404);
|
|
|
|
$subdivisions = DB::table('country_subdivisions')
|
|
->where('country_id', $country->id)
|
|
->orderBy('sort_order')
|
|
->orderBy('name')
|
|
->get()
|
|
->map(fn ($subdivision) => [
|
|
'id' => $subdivision->id ?? null,
|
|
'country_id' => $subdivision->country_id ?? null,
|
|
'code' => $subdivision->code ?? null,
|
|
'name' => $subdivision->name ?? null,
|
|
'type' => $subdivision->type ?? null,
|
|
'parent_code' => $subdivision->parent_code ?? null,
|
|
'is_active' => (bool) ($subdivision->is_active ?? true),
|
|
])
|
|
->values();
|
|
|
|
return response()->json(['data' => $subdivisions]);
|
|
})->name('countries.api.subdivisions.compat');
|