PHPackages                             apriil/postal-codes - 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. apriil/postal-codes

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

apriil/postal-codes
===================

Eloquent model for Norwegian postal codes

v1.1.1(2mo ago)011MITPHPPHP &gt;=8.1

Since May 20Pushed 2mo agoCompare

[ Source](https://github.com/Apriil-Digital/postal-codes)[ Packagist](https://packagist.org/packages/apriil/postal-codes)[ Docs](https://github.com/apriil-digital/postal-codes)[ RSS](/packages/apriil-postal-codes/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (6)Dependencies (2)Versions (7)Used By (0)

Norwegian Postal Codes
======================

[](#norwegian-postal-codes)

An Eloquent model with every Norwegian postal code (`postnummer`), place name (`poststed`), and delivery category, ready to query in Laravel or any PHP app that uses Illuminate Database.

The dataset lives in memory via [Sushi](https://github.com/calebporzio/sushi)—no migrations, seeders, or external API calls. Install the package and query postal codes like any other Eloquent model.

Features
--------

[](#features)

- **5,122 postal codes** bundled in the package
- **Standard Eloquent API** — `find`, `where`, `exists`, relationships, and the rest
- **Zero database setup** — Sushi builds a temporary SQLite table from the embedded data
- **Leading zeros preserved** — postal codes are stored as four-character strings (e.g. `0001`, `7030`)
- **Delivery categories** — each code is tagged as street address, PO box, both, or service point via a typed `Category` enum

Prerequisites
-------------

[](#prerequisites)

- **PHP** 8.1 or newer
- **PDO SQLite** extension (`pdo_sqlite`) — required by Sushi
- **Laravel** 8.69 or newer

Installation
------------

[](#installation)

Install via Composer:

```
composer require apriil/postal-codes
```

Usage
-----

[](#usage)

Import the model and use familiar Eloquent methods.

### Look up a postal code

[](#look-up-a-postal-code)

```
use Apriil\PostalCodes\PostalCode;

$postal = PostalCode::find('0001');

$postal->id;       // "0001"
$postal->name;     // "Oslo"
$postal->category; // Category::Mailbox
```

### Filter by category

[](#filter-by-category)

Each postal code has a `category` that describes what kind of delivery it supports. The value is cast to the `Category` backed enum:

```
use Apriil\PostalCodes\Enums\Category;
use Apriil\PostalCodes\PostalCode;

// Street-address codes only
$streetCodes = PostalCode::where('category', Category::Address)->get();

// PO box codes in Oslo
$osloPostboxes = PostalCode::where('name', 'Oslo')
    ->where('category', Category::Mailbox)
    ->get();

// Compare on the model
$postal = PostalCode::find('0050');
$postal->category === Category::Address; // true
```

Enum caseStored valueMeaning`Category::Address``G`Street address delivery only`Category::Mailbox``P`PO box (`postboks`) delivery only`Category::Both``B`Both street address and PO box`Category::ServicePoint``S`Service point / pickup locationMost codes are street-address (`G`) or PO box (`P`). `Both` and `ServicePoint` are less common but matter when you need to restrict which codes users can enter (for example, only `G` for home delivery forms).

### Validate that a postal code exists

[](#validate-that-a-postal-code-exists)

```
$isValid = PostalCode::where('id', '7030')->exists();
```

### Find all codes for a place

[](#find-all-codes-for-a-place)

Many places share one name (e.g. several codes for Oslo):

```
$osloCodes = PostalCode::where('name', 'Oslo')->get();
```

### Use in validation (Laravel)

[](#use-in-validation-laravel)

```
use Apriil\PostalCodes\PostalCode;
use Illuminate\Validation\Rule;

$request->validate([
    'postal_code' => [
        'required',
        'digits:4',
        Rule::exists(PostalCode::class, 'id'),
    ],
]);
```

### Autocomplete or select options

[](#autocomplete-or-select-options)

```
$postalCodes = PostalCode::query()
    ->orderBy('name')
    ->orderBy('id')
    ->get(['id', 'name', 'category']);
```

### Relationships

[](#relationships)

Treat `PostalCode` like any other Eloquent model. For example, a `User` model can reference a postal code:

```
use Apriil\PostalCodes\PostalCode;

class User extends Model
{
    public function postalCode()
    {
        return $this->belongsTo(PostalCode::class, 'postal_code', 'id');
    }
}
```

Model reference
---------------

[](#model-reference)

ColumnTypeDescription`id`stringFour-digit Norwegian postal code (primary key)`name`stringPlace name (`poststed`)`category``Category`Delivery type (`G`, `P`, `B`, or `S`) — see aboveThe model does not use timestamps (`created_at` / `updated_at`).

License
-------

[](#license)

MIT © [Apriil Digital](https://apriil.no)

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance87

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community7

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 ~0 days

Total

6

Last Release

64d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.4

v1.1.0PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/14291825?v=4)[Thomas Alrek](/maintainers/thomas-alrek)[@thomas-alrek](https://github.com/thomas-alrek)

![](https://www.gravatar.com/avatar/93300f1d57e4f198d035a680f1de6a8635becc12052acbe74a08f578b124863b?d=identicon)[cathrinevaage](/maintainers/cathrinevaage)

---

Top Contributors

[![thomas-alrek](https://avatars.githubusercontent.com/u/14291825?v=4)](https://github.com/thomas-alrek "thomas-alrek (7 commits)")

### Embed Badge

![Health badge](/badges/apriil-postal-codes/health.svg)

```
[![Health](https://phpackages.com/badges/apriil-postal-codes/health.svg)](https://phpackages.com/packages/apriil-postal-codes)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M98](/packages/mongodb-laravel-mongodb)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k32.6M46](/packages/kirschbaum-development-eloquent-power-joins)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[bavix/laravel-wallet

It's easy to work with a virtual wallet.

1.3k1.3M19](/packages/bavix-laravel-wallet)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)[laravel-liberu/laravel-gedcom

A package that converts gedcom files to Eloquent models

782.5k1](/packages/laravel-liberu-laravel-gedcom)

PHPackages © 2026

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