Files
Verde-Web/app/Http/Controllers/Api/V1/Geo/CityMunicipalityController.php
admin c8404564fe feat(backend): complete Modules 2 + 3 (geo + user management)
Module 2 — Geographic Data: PSGC tables (regions/provinces/cities/
barangays) with native geometry(polygon|point, 4326) columns; cascading
dropdown endpoints; ST_Contains-based GPS resolution; service-area CRUD
with barangay attach/detach; SamplePsgcSeeder + psgc:import command.

Module 3 — User Management: 5 role-specific profile tables (driver/
helper/scanner/store_partner with verification_status + rejection
reason); profile auto-created on register; admin user CRUD with
filters/pagination, suspend/activate, profile approve/reject;
self-service /me + /me/profile with role-aware validation that blocks
self-approval and resets rejected profiles to pending on resubmit.

69 feature tests passing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 23:59:56 +08:00

39 lines
1.6 KiB
PHP

<?php
namespace App\Http\Controllers\Api\V1\Geo;
use App\Http\Controllers\Api\V1\ApiController;
use App\Http\Resources\CityMunicipalityResource;
use App\Models\CityMunicipality;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class CityMunicipalityController extends ApiController
{
public function __invoke(Request $request): JsonResponse
{
$request->validate([
'province' => ['nullable', 'string', 'max:32'],
'province_id' => ['nullable', 'integer'],
'region' => ['nullable', 'string', 'max:32'],
'type' => ['nullable', 'in:city,municipality,sub_municipality'],
]);
$cities = CityMunicipality::query()
->when($request->filled('province'), function ($q) use ($request) {
$q->whereHas('province', fn ($p) => $p->where('psgc_code', $request->string('province'))
->orWhere('code', $request->string('province')));
})
->when($request->filled('province_id'), fn ($q) => $q->where('province_id', $request->integer('province_id')))
->when($request->filled('region'), function ($q) use ($request) {
$q->whereHas('province.region', fn ($r) => $r->where('psgc_code', $request->string('region'))
->orWhere('code', $request->string('region')));
})
->when($request->filled('type'), fn ($q) => $q->where('type', $request->string('type')))
->orderBy('name')
->get();
return $this->ok(CityMunicipalityResource::collection($cities));
}
}