firevel/model-random-id

Model random ID generator for Laravel.

0.0.3 2022-05-20 18:41 UTC

This package is auto-updated.

Last update: 2024-04-13 22:04:55 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;