Download the PHP package attla/ulid without Composer
On this page you can find all versions of the php package attla/ulid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package ulid
Short Description Universally Unique Lexicographically Sortable Identifier (ULID) implementation for Attla and Laravel.
License MIT
Homepage https://github.com/attla/ulid
Informations about the package ulid
Attla ULID
A PHP port of ulid/javascript with some minor improvements.
Universally Unique Lexicographically Sortable Identifier
UUID can be suboptimal for many uses-cases because:
- It isn't the most character efficient way of encoding 128 bits of randomness
- UUID v1/v2 is impractical in many environments, as it requires access to a unique, stable MAC address
- UUID v3/v5 requires a unique seed and produces randomly distributed IDs, which can cause fragmentation in many data structures
- UUID v4 provides no other information than randomness which can cause fragmentation in many data structures
Instead, herein is proposed ULID:
- 128-bit compatibility with UUID
- 1.21e+24 unique ULIDs per millisecond
- Lexicographically sortable!
- Canonically encoded as a 26 character string, as opposed to the 36 character UUID
- Uses Crockford's base32 for better efficiency and readability (5 bits per character)
- Case insensitive
- No special characters (URL safe)
- Monotonic sort order (correctly detects and handles the same millisecond)
You can read more here
What are the benefits?
- With distributed systems you can be pretty confident that the primary key’s will never collide.
- When building a large scale application when an auto increment primary key is not ideal.
- It makes replication trivial (as opposed to int’s, which makes it REALLY hard)
- Safe enough doesn’t show the user that you are getting information by id, for example
https://example.com/item/10
Installation
Usage
Use the methods get()
or toString()
to get the ULID as a string on ULID instances.
Migrations
When using the migration you should change $table->increments('id') or $table->id() to:
Simply, the schema seems something like this.
If the related model is using an ULID, the column type should reflect that also.
The ULID blueprint parameter is optional. But below is an example of how to use it.
Models
To set up a model to use ULID, simply use the HasUlid trait.
Controller
When you create a new instance of a model which uses ULIDs, this package will automatically add ULID as id of the model.
Testing
Benchmark
License
This package is licensed under the Octha.