PHPackages                             assumilhig/laravel-key-generator - 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. assumilhig/laravel-key-generator

ActiveLibrary

assumilhig/laravel-key-generator
================================

A laravel package that generate a eloquent model keys

1.0.3(4y ago)014MITPHPPHP ^7.4|^8.0

Since Sep 26Pushed 4y ago1 watchersCompare

[ Source](https://github.com/assumilhig/laravel-key-generator)[ Packagist](https://packagist.org/packages/assumilhig/laravel-key-generator)[ Docs](https://github.com/assumilhig/laravel-key-generator)[ RSS](/packages/assumilhig-laravel-key-generator/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)Dependencies (4)Versions (6)Used By (0)

A laravel package that generate a eloquent model keys
=====================================================

[](#a-laravel-package-that-generate-a-eloquent-model-keys)

[![Latest Version on Packagist](https://camo.githubusercontent.com/839450ac277705b0beab9bcd3db9e1282d1791307524892b796fe7c6687808f1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f617373756d696c6869672f6c61726176656c2d6b65792d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/assumilhig/laravel-key-generator)[![Total Downloads](https://camo.githubusercontent.com/654612964024952ba0945732ca52666b8bc993f287eea457a14aff17ab47b449/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f617373756d696c6869672f6c61726176656c2d6b65792d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/assumilhig/laravel-key-generator)[![GitHub Actions](https://github.com/assumilhig/laravel-key-generator/actions/workflows/main.yml/badge.svg)](https://github.com/assumilhig/laravel-key-generator/actions/workflows/main.yml/badge.svg)

This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.

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

[](#installation)

You can install the package via composer:

```
composer require assumilhig/laravel-key-generator
```

You can publish everything with:

```
php artisan vendor:publish --provider="Assumilhig\LaravelKeyGenerator\LaravelKeyGeneratorServiceProvider"
```

This is the contents of the published config file:

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

Usage
-----

[](#usage)

There are two available methods to generate the key:

### Using the Laravel Key Generator

[](#using-the-laravel-key-generator)

```
LaravelKeyGenerator::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 Key

[](#using-the-str-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:

```
namespace App\Models;

use Assumilhig\LaravelKeyGenerator\HasKey;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    use HasKey;
    use HasFactory;

    public $timestamps = false;

    protected $fillable = [
      'key'
    ];
}
```

> 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:

[](#an-example)

**Category Model:** `cat_N6mU3u0aTgktLQnAsxwU`

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 what has changed recently.

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

[](#contributing)

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

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Aljon Sumilhig](https://github.com/assumilhig)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Total

4

Last Release

1662d ago

PHP version history (2 changes)1.0.0PHP ^7.4|^8.0

1.0.1PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/780bb083807b9a2b7bcbbfa1d4852272cb84e2d37ebccc546a3c2387337499eb?d=identicon)[assumilhig](/maintainers/assumilhig)

---

Top Contributors

[![assumilhig](https://avatars.githubusercontent.com/u/33595791?v=4)](https://github.com/assumilhig "assumilhig (12 commits)")

---

Tags

assumilhiglaravel-key-generator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/assumilhig-laravel-key-generator/health.svg)

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

###  Alternatives

[jubeki/laravel-code-style

Combine Custom Fixers with the ruleset of Laravel Pint to fix your code style in Laravel Applications/Packages.

56521.7k8](/packages/jubeki-laravel-code-style)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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