PHPackages                             schoolees/laravel-psgc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. schoolees/laravel-psgc

ActiveLibrary[Database &amp; ORM](/categories/database)

schoolees/laravel-psgc
======================

PSGC for Laravel: migrations, seeders, JSON data, models, services, resources, controllers, and read-only routes.

v1.1.0(2mo ago)21.9kMITPHPPHP ^8.1CI passing

Since Feb 17Pushed 2mo agoCompare

[ Source](https://github.com/Schoolees/schoolees-psgc.package)[ Packagist](https://packagist.org/packages/schoolees/laravel-psgc)[ RSS](/packages/schoolees-laravel-psgc/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (12)Versions (6)Used By (0)

📍PSGC Laravel Package
=====================

[](#psgc-laravel-package)

[![Latest Stable Version](https://camo.githubusercontent.com/298a01aa529d259b01474e8cbc2fd854bac9824489617ef2761227b8224567a8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7363686f6f6c6565732f6c61726176656c2d707367632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/schoolees/laravel-psgc)[![Total Downloads](https://camo.githubusercontent.com/6a912a79f870b5e66fbf42cca8df64372c3c73d6bccc02e41f6a2bf1fe6fe9a8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7363686f6f6c6565732f6c61726176656c2d707367632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/schoolees/laravel-psgc)[![License](https://camo.githubusercontent.com/cb3eb5705b9aae60b63b31f0dd84b745fc3ef2ece2f6666e3c8ebc37226f61ed/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7363686f6f6c6565732f6c61726176656c2d707367632e7376673f7374796c653d666c61742d737175617265)](LICENSE)

A Laravel package for handling **Philippine Standard Geographic Code (PSGC)** data — including Regions, Provinces, Cities/Municipalities, and Barangays.

It comes complete with **migrations**, **seeders**, **JSON data**, **Eloquent models**, **services**, **controllers**, **API resources**, and **routes** following clean Laravel architecture.

---

📦 Features
----------

[](#-features)

- Full PSGC database structure (Regions, Provinces, Cities, Barangays)
- JSON PSGC dataset in `resources/psgc/`
- Database migrations and seeders for an initial data load
- Eloquent models with relationships and searchable fields
- Service layer for clean business logic
- REST API controllers &amp; resources
- Artisan command to regenerate PSGC models
- Ready-to-use API routes for all PSGC endpoints

📋 Requirements
--------------

[](#-requirements)

- PHP &gt;= 8.1
- Laravel 10.x to 13.x
- Laravel 13 requires PHP 8.3+ (per Laravel's support policy)
- MySQL / MariaDB

🤝 Contributing
--------------

[](#-contributing)

Repository development/testing notes are in `CONTRIBUTING.md`.

⚙️ Installation
---------------

[](#️-installation)

**Require the package via Composer:**

```
composer require schoolees/laravel-psgc
```

**Quick installation:**

```
php artisan psgc:install --seed
php artisan psgc:install --force --seed # Overwrite previously published package files
```

By default, the package auto-registers routes at `/{PSGC_API_PREFIX}` and keeps the same URL shape if you later switch to published routes.

**Publishing assets (optional):**

```
# Config
php artisan vendor:publish --tag=psgc-config

# Seeders
php artisan vendor:publish --tag=psgc-seeders

# Routes
php artisan psgc:publish-routes
php artisan psgc:publish-routes --force # Overwrite if re-running

# Resources
php artisan vendor:publish --tag=psgc-resources
php artisan vendor:publish --tag=psgc-resources-classes
```

**Generate PSGC models (optional):**

```
php artisan make:psgc-models
php artisan make:psgc-models --force # Overwrite existing models
php artisan make:psgc-models --softdeletes # Include SoftDeletes trait
```

**Example Request:**

```
# Get all Regions
GET /psgc/regions

# Get Cities in the National Capital Region (NCR)
GET /psgc/cities?region_code=1300000000

# Get the City of Manila
GET /psgc/cities?code=1380600000

# Get Barangays in the City of Manila
GET /psgc/barangays?city_code=1380600000
```

**Example JSON Response:**

```
{
  "code": 200,
  "draw": 1,
  "recordsFiltered": 1,
  "recordsTotal": 1,
  "recordsPerPage": 10,
  "data": [
    {
      "code": "1380600000",
      "name": "City of Manila",
      "province_code": null,
      "region_code": "1300000000"
    }
  ],
  "filters": {
    "code": "1380600000"
  }
}
```

**Filtering and Searching**

You can filter results by passing query parameters. Refer to the `getSearchable()` method on each model for available filterable fields.

**Example: Get cities in the National Capital Region (NCR)**

```
GET /psgc/cities?region_code=1300000000
```

**Example: Search for a city by name**

```
GET /psgc/cities?name=Manila
```

🔍 Searchable Fields
-------------------

[](#-searchable-fields)

Each model has a `getSearchable()` method to define searchable columns for filtering via API.

**Example for a City model:**

```
public function getSearchable(): array
{
    return [
        'query' => ['code', 'region_code', 'province_code', 'is_city'],
        'query_like' => ['name', 'city_class'],
    ];
}
```

🧩 Service Layer
---------------

[](#-service-layer)

The package follows the Service-Controller-Resource pattern for clean, maintainable code.

**Example:**

```
$results = $this->cityService->getCities(
    request()->all(),
    request()->input('order_by', 'name'),
    request()->input('sort_by', 'desc'),
    request()->input('limit', 10),
    request()->input('offset', 0)
);
```

Optional .env overrides
-----------------------

[](#optional-env-overrides)

**To customize API prefix:**

```
PSGC_API_PREFIX=geo # Will change /psgc/regions to /geo/regions.
```

**Route strategy (important):**

- Default: package auto-registers routes via service provider.
- Published routes are appended to `routes/web.php` with the configured PSGC prefix and middleware so they keep the same `/{prefix}/*` URLs.
- If you want to use published `routes/psgc.php`, disable package route registration to avoid duplicates:

```
// config/psgc.php
'register_package_routes' => false,
```

**Pagination safety override:**

```
// config/psgc.php
'max_limit' => 100, // caps ?limit=...
```

**Response format override:**

```
// config/psgc.php
'response_format' => 'datatable', // or 'pagination'
```

📜 License
---------

[](#-license)

This package is open-sourced software licensed under the MIT license.

🏢 About
-------

[](#-about)

Developed &amp; maintained by Schoolees as part of the Schoolees Educational Suite.

📊 Data Source
-------------

[](#-data-source)

This package uses the official **Philippine Standard Geographic Code (PSGC)** dataset published by the **Philippine Statistics Authority (PSA)**.

Latest Dataset Used: [📄 PSGC 2Q 2025 Publication Datafile (Excel)](https://psa.gov.ph/system/files/scd/PSGC-2Q-2025-Publication-Datafile.xlsx)

Attribution: Philippine Statistics Authority — *Philippine Standard Geographic Code (PSGC)*

Update Frequency: Quarterly (based on PSA publication schedule)

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance85

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~20 days

Total

4

Last Release

77d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f80efb980bf06a05fb30e05c8cd52e4bef6372144667b93b38e3feb646d70719?d=identicon)[rpbaguio](/maintainers/rpbaguio)

---

Top Contributors

[![rpbaguio](https://avatars.githubusercontent.com/u/2038712?v=4)](https://github.com/rpbaguio "rpbaguio (79 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/schoolees-laravel-psgc/health.svg)

```
[![Health](https://phpackages.com/badges/schoolees-laravel-psgc/health.svg)](https://phpackages.com/packages/schoolees-laravel-psgc)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k29.9M146](/packages/laravel-cashier)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M132](/packages/laravel-pulse)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1235.9k20](/packages/fleetbase-core-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
