PHPackages                             juststeveking/laravel-key-factory - 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. juststeveking/laravel-key-factory

ActiveLibrary

juststeveking/laravel-key-factory
=================================

A simple package to generate Eloquent Model Keys

1.1.0(3y ago)61.3k↑41.7%3[1 issues](https://github.com/JustSteveKing/laravel-key-factory/issues)MITPHPPHP ^8.0

Since Jul 5Pushed 3y ago1 watchersCompare

[ Source](https://github.com/JustSteveKing/laravel-key-factory)[ Packagist](https://packagist.org/packages/juststeveking/laravel-key-factory)[ Docs](https://github.com/juststeveking/laravel-key-factory)[ GitHub Sponsors](https://github.com/JustSteveKing)[ RSS](/packages/juststeveking-laravel-key-factory/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (8)Versions (3)Used By (0)

A simple package to generate Eloquent Model Keys
================================================

[](#a-simple-package-to-generate-eloquent-model-keys)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1c4cdbb768754aac508e08326dc7a0045cfa71a93943090ecdda31e0a260cf9c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a75737473746576656b696e672f6c61726176656c2d6b65792d666163746f72792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juststeveking/laravel-key-factory)[![GitHub Tests Action Status](https://camo.githubusercontent.com/119d626caf5dc63787f7da17e25b7d781f5d63913ece26aae095be0a5cf3cfc1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6a75737473746576656b696e672f6c61726176656c2d6b65792d666163746f72792f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/juststeveking/laravel-key-factory/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/197cc0efdcd2d0c0b4da39639971a4d3be9251ec6f5ccc954a6600be0394e5f1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6a75737473746576656b696e672f6c61726176656c2d6b65792d666163746f72792f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/juststeveking/laravel-key-factory/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/1fe899db763a6d69de231bbfb64b5aa203973f5e82f28b80aaa93233b1d86f59/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a75737473746576656b696e672f6c61726176656c2d6b65792d666163746f72792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juststeveking/laravel-key-factory)

Laravel Key Factory is a simple package to generate Eloquent Model Keys for your models easily. This is something I do quite often, instead of using UUID's which can be quite unfriendly to look at, I use Model keys which are unique strings generated for each model.

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

[](#installation)

You can install the package via composer:

```
composer require juststeveking/laravel-key-factory
```

You can publish and run the migrations with:

You can publish the config file with:

```
php artisan vendor:publish --provider="JustSteveKing\KeyFactory\KeyFactoryServiceProvider" --tag="key-factory-config"
```

This is the contents of the published config file:

```
return [
    'key' => [
        'length' => 20,
    ]
];
```

Usage
-----

[](#usage)

This is a very simple to use package. There are two available methods to generate the key:

### Using the Key Factory

[](#using-the-key-factory)

```
$key = \JustSteveKing\KeyFactory\KeyFactory::generate(
    prefix: 'test', // what you want to prefix your keys with.
    length: 20, // optional - the default of 20 is set in the config.
);
```

### Using the Str helper

[](#using-the-str-helper)

```
$key = \Illuminate\Support\Str::key(
    prefix: 'test', // what you want to prefix your keys with.
    length: 20, // optional - the default of 20 is set in the config.
);
```

Eloquent Integration
--------------------

[](#eloquent-integration)

There is an eloquent model trait available to use called `HasKey` which will:

> When you are creating an eloquent model, the trait will be booted. It will get the first 3 characters of the Model name, force them to lowercase and append a "\_" and use this as the prefix for the Key Factory

An example:

- User Model: `use_12345678909876543212`
- Project Model: `pro_12345678909876543212`

Currently this isn't a configured option as it is easy to override or implement yourself.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Steve McDougall](https://github.com/JustSteveKing)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 71% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.5% 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 ~498 days

Total

2

Last Release

1223d ago

### Community

Maintainers

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

---

Top Contributors

[![JustSteveKing](https://avatars.githubusercontent.com/u/6368379?v=4)](https://github.com/JustSteveKing "JustSteveKing (7 commits)")[![UendelC](https://avatars.githubusercontent.com/u/21681869?v=4)](https://github.com/UendelC "UendelC (1 commits)")

---

Tags

laravelJustSteveKinglaravel-key-factory

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/juststeveking-laravel-key-factory/health.svg)

```
[![Health](https://phpackages.com/badges/juststeveking-laravel-key-factory/health.svg)](https://phpackages.com/packages/juststeveking-laravel-key-factory)
```

###  Alternatives

[juststeveking/laravel-transporter

Transporter is a futuristic way to send API requests in PHP. This is an OOP approach to handle API requests.

480188.7k2](/packages/juststeveking-laravel-transporter)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13662.4k1](/packages/ralphjsmit-laravel-helpers)[basillangevin/laravel-data-json-schemas

Transforms Spatie Data objects into JSON Schemas with built-in validation

136.9k1](/packages/basillangevin-laravel-data-json-schemas)

PHPackages © 2026

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