PHPackages                             amirkacem/model-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. [Database &amp; ORM](/categories/database)
4. /
5. amirkacem/model-key-factory

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

amirkacem/model-key-factory
===========================

A simple package to generate Eloquent Model Keys

v1.0.1(4y ago)05MITPHPPHP ^8.0

Since Apr 9Pushed 4y ago1 watchersCompare

[ Source](https://github.com/amirKacem/model-key-factory)[ Packagist](https://packagist.org/packages/amirkacem/model-key-factory)[ Docs](https://github.com/amirKacem/model-key-factory.git)[ RSS](/packages/amirkacem-model-key-factory/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)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/5b8f929d95bea4d849c8c3ff66a514565a2b7c3b50f6cfc9eada02ddcb740e80/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7061636b61676973742d76312e302e312d626c7565)](https://packagist.org/packages/amirkacem/model-key-factory)[![Stars](https://camo.githubusercontent.com/5b26836c82aa9f1c40009a99f0acbb971af5d279345efaf1d9cd92ee31523663/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f616d69724b6163656d2f6d6f64656c2d6b65792d666163746f72793f636f6c6f723d73756363657373)](https://github.com/amirKacem/model-key-factory/stargazers)

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

[](#installation)

```
composer require amirkacem/model-key-factory
```

You can publish the config file with:

```
php artisan vendor:publish --provider="Eloquent\KeyFactory\KeyFactoryServiceProvider" --tag="model-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 = \Eloquent\KeyFactory\KeyFactory::generate(
    prefix: 'tests', // 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: 'tests', // what you want to prefix your keys with.
    length: 20, // optional - the default of 20 is set in the config.
);
```

### Test

[](#test)

```
vendor/bin/phpunit
```

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

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

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

2

Last Release

1492d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5e3e13f0b8a8be5e4a153867efb99a15afc180f4255d32d6aeb5dba451353aa0?d=identicon)[amirKacem](/maintainers/amirKacem)

---

Top Contributors

[![amirKacem](https://avatars.githubusercontent.com/u/29010579?v=4)](https://github.com/amirKacem "amirKacem (7 commits)")

---

Tags

laravelmodel-key-factory

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/amirkacem-model-key-factory/health.svg)

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

###  Alternatives

[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[spatie/laravel-model-flags

Add flags to Eloquent models

4301.1M1](/packages/spatie-laravel-model-flags)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[spatie/laravel-sql-commenter

Add comments to SQL queries made by Laravel

1931.4M1](/packages/spatie-laravel-sql-commenter)[spatie/laravel-deleted-models

Automatically copy deleted records to a separate table

409109.8k4](/packages/spatie-laravel-deleted-models)[wnx/laravel-backup-restore

A package to restore database backups made with spatie/laravel-backup.

203330.1k2](/packages/wnx-laravel-backup-restore)

PHPackages © 2026

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