Download the PHP package rawilk/human-keys without Composer

On this page you can find all versions of the php package rawilk/human-keys. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package human-keys

human-keys

Latest Version on Packagist Tests Total Downloads PHP from Packagist License

social image

Human Keys offers an alternative to using UUIDs for your Laravel Models. By default, it generates ksuids, similar to what Stripe uses for their resources. Ksuids are human-readable and sortable.

Example:

Installation

You can install the package via composer:

You can publish the config file with:

If you are using the KsuidGenerator (which is the default), you will need to install the tuupola/ksuid package:

See Using a Different Generator for more information.

You can view the default configuration here: https://github.com/rawilk/human-keys/blob/main/config/human-keys.php

Usage

To get started, use the HasHumanKey trait on your model:

Using a Different Generator

By default, the package is configured to use the KsuidGenerator, however you may define a custom generator to use under the generator key in the config file.

Below you will find out how to use the different generators that are included with this package, and how to create your own.

KsuidGenerator

This is the default generator that is used. You will need to install the tuupola/ksuid package to use it. This generator will generate something like this: pos_2JvL8Gv5mirjbIVAlSRFrC8EaWR.

SnowflakeGenerator

This generator generates IDs based on the Snowflake Algorithm announced by Twitter. You will need to install the godruoyi/php-snowflake package to use it. This generator will generate something like this: pos_451734027389370636.

UuidGenerator

As of v1.1.0, you can use the UuidGenerator, which generates ids using Laravel's Str::uuid() helper. Ids generated with this generator will look like: pos_b8a34e34553a41b885ae218ae81abd42. The only requirement for this generator is to register it in the config file; there are no external dependencies that are required for it.

Custom Generator

You may define your own generator by implementing the Rawilk\HumanKeys\Contracts\KeyGenerator contract. From the generator, you may return an ID based on your application's requirements.

Then, in the config file, you may specify your generator:

Overriding the Key Prefix

By default, the key the first 3 characters of the model's class name. You may override this by defining a humanKeyPrefix method on your model:

Using it For Other Columns

By default, the HasHumanKey trait will generate an ID for your model's primary key column. This may not be what you want, however. In your model, you may override the humanKeys method and return a listing of the columns that should be generated for.

Now the human_key column will be generated for instead of the primary key. This is useful if your model is already using auto-incrementing IDs or if you are using UUID or ULID for your primary keys. The HasHumanKey trait is fully compatible with Laravel's HasUuids or HasUlids traits.

If you really need to, you may even override the newHumanKey method on your model to generate a custom ID in a way of your choosing, however in most cases this shouldn't be necessary.

Scripts

Setup

For convenience, you can run the setup bin script for easy installation for local development.

Formatting

Although formatting is done automatically via workflow, you can format php code locally before committing with a composer script:

Testing

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security

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

Alternatives

This package is very similar to the laravel-human-keys package by oneduo, however I created my own version because I wanted more flexibility in which columns IDs are generated for.

Other alternatives include:

Credits

License

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


All versions of human-keys with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1|^8.2|^8.3
illuminate/contracts Version ^10.0|^11.0
spatie/laravel-package-tools Version ^1.14
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rawilk/human-keys contains the following files

Loading the files please wait ....