PHPackages                             jkbennemann/laravel-external-key - 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. jkbennemann/laravel-external-key

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jkbennemann/laravel-external-key
================================

A simple package to generate Eloquent Model Keys

05PHP

Since Dec 4Pushed 3y ago1 watchersCompare

[ Source](https://github.com/jkbennemann/laravel-external-key)[ Packagist](https://packagist.org/packages/jkbennemann/laravel-external-key)[ RSS](/packages/jkbennemann-laravel-external-key/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)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

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![jkbennemann](https://avatars.githubusercontent.com/u/25330395?v=4)](https://github.com/jkbennemann "jkbennemann (6 commits)")

### Embed Badge

![Health badge](/badges/jkbennemann-laravel-external-key/health.svg)

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

###  Alternatives

[prism-php/prism

A powerful Laravel package for integrating Large Language Models (LLMs) into your applications.

2.3k2.3M66](/packages/prism-php-prism)

PHPackages © 2026

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