Download the PHP package riipandi/laravel-optikey without Composer
On this page you can find all versions of the php package riipandi/laravel-optikey. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-optikey
Laravel OptiKey
Use UUID, Ulid, or nanoid as optional or primary key in Laravel.
This package adds a very simple trait to automatically generate a UUID, Ulid, or nanoid for your Models.
✌️ Using as Secondary Key
1. Update your schemas
First, you need to add an extra column in your migration. For example:
Sample migration:
2. Add the trait
Add the trait to your model (pick one between HasUuidKey
, HasUlidKey
, or HasNanoidKey
):
3. Get Record using the key
Using scope:
Or, using static find method:
☝️ Using as Primary Key
You need to change the primary key field type in your migration. For example:
Add second trait to use as primary key:
It simply tells Laravel that your primary key isn't an auto-incrementing integer, so it will treat the value correctly.
📝 Important Note
You can use prefix
option to add a prefix to the generated key.
- [x] Default lengt for Ulid is 26 characters.
- [x] Default length for nanoid is 16 characters.
- [x] If you want to use prefix, set larger length.
Licence
This project is licensed under MIT: https://aris.mit-license.org
Copyrights in this project are retained by their contributors. No copyright assignment is required to contribute to this project.
This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.
Please see license file for more information.
All versions of laravel-optikey with dependencies
laravel/framework Version ^5.8|^6.0|^7.0|^8.0|^8.1|^9.0|^10.0|^11.0
hidehalo/nanoid-php Version ^1.1
robinvdvleuten/ulid Version ^5.0