New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

juststeveking/laravel-key-factory

A simple package to generate Eloquent Model Keys
4,293 6

Larablocks Analysis

juststeveking/laravel-key-factory works with Laravel 8 and 9 (latest release 1.1.0, Nov 15, 2022), all past end of life (the last on Feb 6, 2024): no more fixes, even for security.

Recommendation checks

Not advised

Not advised: no release or commit in over 2 years.

  • No release or commit in over 2 years
  • Supports only Laravel 8 and 9, past end of life since Feb 6, 2024
  • No release in the last 12 months (last: Nov 15, 2022)
  • 435 downloads a month (needs 10,000)
  • 6 GitHub stars (needs 100)

State

Likely abandoned
  • No release or commit in over 2 years.
  • Last stable release: Nov 15, 2022.
  • No releases in the last 12 months.
  • First released: Jul 5, 2021.
  • Monthly downloads: 435.
  • 1 open issue on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Dec 5, 2026.

Install
composer require juststeveking/laravel-key-factory
Latest Version:1.1.0
PHP:^8.0
Laravel:8 · 9
License:MIT
Last Updated:Nov 15, 2022
Links: GitHub  ·  Packagist
Maintainer: JustSteveKing

A simple package to generate Eloquent Model Keys

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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

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

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

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

$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

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

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Related Packages

juststeveking/laravel-postcodes

A service wrapper around postcodes.io

167,073 82
juststeveking/laravel-transporter

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

215,024 478
juststeveking/laravel-feature-flags

A simple to use Feature Flags package for Laravel

59,700 177
juststeveking/eloquent-log-driver

A Laravel Log Driver for Eloquent

3,242 7
juststeveking/companies-house-laravel

A Laravel wrapper to get companies house information and validate company number...

4,166 22

Version History

Version Released PHP Laravel License
1.1.0 ^8.0 ^8.37 || 9.x MIT
1.0.0 ^8.0 ^8.37 MIT