40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Services\RegisterLocationService;
|
|
use Illuminate\Http\Request;
|
|
|
|
class RegisterLocationController extends Controller
|
|
{
|
|
public function countries()
|
|
{
|
|
$paths = [
|
|
storage_path('app/geo/countriesAndStates.json'),
|
|
public_path('assets/data/countriesAndStates.json'),
|
|
public_path('data/countriesAndStates.json'),
|
|
];
|
|
|
|
foreach ($paths as $path) {
|
|
if (is_readable($path)) {
|
|
return response()->file($path, [
|
|
'Content-Type' => 'application/json; charset=UTF-8',
|
|
'Cache-Control' => 'public, max-age=86400',
|
|
]);
|
|
}
|
|
}
|
|
|
|
return response()->json(['error' => 'Countries data not found'], 404);
|
|
}
|
|
|
|
public function cities(Request $request, RegisterLocationService $locations)
|
|
{
|
|
$country = (string) $request->query('country', '');
|
|
$state = (string) $request->query('state', '');
|
|
|
|
return response()->json(
|
|
$locations->getCitiesForCountryState($country, $state)
|
|
);
|
|
}
|
|
}
|