firevel / model-random-id
Model random ID generator for Laravel.
Installs: 6 178
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
This package is auto-updated.
Last update: 2024-11-13 23:34:34 UTC
README
This package automatically generate primary id using cryptographic random integers that fit MySQL BIGINT
column and JavaScript MAX_SAFE_INTEGER
.
Purpose
Systems using distributed databases like Cloud Spanner or Firestore shouldn't use incremental id's to avoid bottlenecks. UUID can be used as an alternative but long strings can cause performance issues and UX issues. Random BIGINT is a middle ground between incremental id and UUID.
Installation
Make sure your model id is a BIGINT for example: $table->bigInteger('id')->unsigned()->primary();
.
Add to your model trait use \Firevel\ModelRandomId\HasRandomId;
and
/**
* Primary key incrementing.
*
* @var bool
*/
public $incrementing = false;