PHPackages                             sirmathays/prefixed-id - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. sirmathays/prefixed-id

Abandoned → [lyhty/prefixed-id](/?search=lyhty%2Fprefixed-id)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

sirmathays/prefixed-id
======================

Package for adding prefixes to model keys in Laravel.

v2.0(4y ago)02.8kMITPHPPHP &gt;=7.4

Since May 14Pushed 3y ago1 watchersCompare

[ Source](https://github.com/sirmathays/prefixed-id)[ Packagist](https://packagist.org/packages/sirmathays/prefixed-id)[ RSS](/packages/sirmathays-prefixed-id/feed)WikiDiscussions master Synced today

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

Prefixed IDs
============

[](#prefixed-ids)

This package will provide models the ability to have a prefixed id in your system, while still having the database value being just the usual id.

Config
------

[](#config)

Run following command to publish the config file:

```
php artisan vendor:publish --provider="SirMathays\PrefixedId\PrefixedIdServiceProvider"
```

You should set up the models that you want to have ids with prefixes, you should also apply HasPrefixedId trait to the model.

Example
-------

[](#example)

Model with a prefixed id would work the following way:

```
use App\Models\Human;

$human = Human::pidFindOrFail("H-1");
$human->pid; // Prints "H-1"
$human->id; // Prints 1
```

Route binding
-------------

[](#route-binding)

The package automatically binds the models set up in the config file to use prefixes in routing.

### Model specific binding

[](#model-specific-binding)

A model with a prefixed id set up would behave in a following way: `project.test/humans/H-1`

**web.php**

```
use Illuminate\Support\Facades\Route;

Route::get('humans/{human}', [HumanController::class, 'show']);
```

> You can apply an optional prefix to the binding in the config. E.g. `humans/{pid_human}` with `pid_` being the applied prefix. This would keep the Laravel's default binding to the model's key without the prefix.

**HumanController.php**

```
public function show(Request $request, Human $human)
{
    //
}
```

As you can see, setting up the model binding works the same as without the prefixed id.

### Generic model binding

[](#generic-model-binding)

The package also provides more generic routing. An example follows:

**web.php**

```
use Illuminate\Support\Facades\Route;

Route::get('resources/{prefixedModel}', [ResourceController::class, 'show']);
```

> You can change the route binding name in the config.

**ResourceController.php**

```
public function show(Request $request, Model $model)
{
    //
}
```

With a route setup like this, both `project.test/resources/H-1` and `project.test/resources/D-1` would work and would return a Human model instance and a Dog model instance respectively.

This way you can have one route for returning any type of a model, as long as it is set up in config.

Prefixed id helper class
------------------------

[](#prefixed-id-helper-class)

You can utilize PrefixedId class to find instances in a following way:

```
use SirMathays\PrefixedId\Facades\PrefixedId;

$human = PrefixedId::findModel('H-1');
$dog = PrefixedId::findModel('D-1');
```

The find methods would return instances of `App\Models\Human` and `App\Models\Dog` respectively.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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

Recently: every ~67 days

Total

6

Last Release

1585d ago

Major Versions

v1.3.1 → v2.02022-02-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/2cd5d6f2caaea83278fd1552c5bdc1b30b4164890ba0801a718dc20efa93738c?d=identicon)[TruecapeDev](/maintainers/TruecapeDev)

---

Top Contributors

[![sirmathays](https://avatars.githubusercontent.com/u/37704147?v=4)](https://github.com/sirmathays "sirmathays (10 commits)")

---

Tags

laravelmodelprefixid

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sirmathays-prefixed-id/health.svg)

```
[![Health](https://phpackages.com/badges/sirmathays-prefixed-id/health.svg)](https://phpackages.com/packages/sirmathays-prefixed-id)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

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

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M94](/packages/mongodb-laravel-mongodb)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M184](/packages/laravel-ai)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

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

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)[wearepixel/laravel-cart

A cart implementation for Laravel

1374.8k](/packages/wearepixel-laravel-cart)

PHPackages © 2026

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