Download the PHP package firevel/model-random-id without Composer

On this page you can find all versions of the php package firevel/model-random-id. 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 model-random-id

Model Random ID

A Laravel trait that automatically assigns a cryptographically random integer as the primary key of an Eloquent model. Ids fit in a MySQL BIGINT column and stay within JavaScript's Number.MAX_SAFE_INTEGER, so they round-trip safely through JSON and JS clients.

Why random BIGINT?

Distributed databases such as Cloud Spanner and Firestore suffer hotspots when ids are monotonically incrementing. UUIDs avoid that problem but are long, hurt index locality, and look ugly in URLs. A random BIGINT is the middle ground — fixed-width, numeric, indexable, and collision-resistant within the 2^53 range.

Installation

Install the package via Composer:

Usage

Make the primary key a BIGINT in your migration:

Add the trait to your model:

That's it. The trait disables auto-increment for you and assigns a random id on saving if the key column is empty.

Using a non-primary-key column

If you want to populate a column other than the primary key, set $randomIdKeyName:

Customizing the range

The trait exposes two properties you can override per-model:

Property Default Meaning
$minimumRandomId 3656158440062976 Lower bound. Equals "10000000000" parsed as base-36, which guarantees every id is at least 11 characters when rendered in base-36.
$maximumRandomId 9007199254740991 Upper bound. Equals Number.MAX_SAFE_INTEGER (2^53 − 1) and fits in MySQL BIGINT.

You can also override generateRandomInteger() if you need a different generation strategy entirely.

How it works

Limitations

Random number generation reduces the risk of ID collisions but is not immune to them. The more rows you insert, the higher the chance of a collision due to the birthday paradox — random sampling within a finite range (here, 2^53) makes overlap increasingly likely as the table grows. For use cases involving tens of millions of rows or extremely high throughput, consider pre-generating a pool of unique ids and handing them out, or wrapping inserts in retry-on-duplicate-key logic.

License

MIT — see LICENSE.


All versions of model-random-id with dependencies

PHP Build Version
Package Version
No informations.
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 firevel/model-random-id contains the following files

Loading the files please wait ...