Download the PHP package intrfce/laravel-public-ids without Composer

On this page you can find all versions of the php package intrfce/laravel-public-ids. 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 laravel-public-ids

Note: This is not production ready, and the docs aren't ready yet.

Laravel Public IDs

Stripe-style public identifiers for Eloquent models — user_3kQ4mZp8Vh7kQp2Rt5Nx9, cus_0192f8a1... — that are a reversible base62 encoding of the model's UUID v7 primary key.

Unlike a real Stripe ID (an opaque random token), this ID decodes back to the UUID with pure math — no database lookup. That makes it fast and stateless, at the cost of not being opaque (see Caveats).

Requirements

Installation

The service provider is auto-discovered.

Setup

1. Add the trait and declare a prefix

Each model owns its prefix, returned from an idPrefix() method on the class — there is no central registry to keep in sync:

The trait builds on Laravel's own HasUuids, so the key is a non-incrementing string auto-populated with a UUID v7 on create (override newUniqueId() to change that). idPrefix() is abstract — a model that uses the trait without implementing it won't compile, so there is no runtime "missing prefix" state to guard against.

2. Use a UUID primary key in your migration

Usage

Reading the ID

The raw UUID stays the ORM key — relationships, eager loading, and foreign keys are never touched, so everything keeps working normally.

JSON / API output

toArray() and toJson() present the Public ID as id and hide the raw UUID:

Route model binding

URLs use the Public ID automatically, and implicit binding decodes it:

Querying

find(), findOrFail(), findMany(), destroy(), and whereIn('id', …) all accept either a bare UUID or a Public ID:

Assigning the key

Note the deliberate asymmetry: you may assign a Public ID, but reading $user->id returns the raw UUID. Read $user->public_id for the prefixed form.

Validation

Laravel's built-in exists rule runs a raw query and cannot match a Public ID against a UUID column (it silently fails on MySQL and 500s on Postgres). Use the decode-aware rule instead, naming the model directly:

Bad input (malformed tail, wrong prefix) fails as a normal validation message — it never throws. The target model must use HasPublicIds; its prefix is read from idPrefix().

Exceptions

All extend Intrfce\PublicIds\Exceptions\PublicIdException:

Exception When
PrefixMismatchException assigning/querying with another model's prefix
InvalidPublicIdException malformed value or a tail that isn't valid base62

How it works

"The id" is two things that this package deliberately keeps separate:

Decoding is pure integer arithmetic over the UUID's 16 raw bytes (no ext-gmp/ext-bcmath required). The full rationale for every decision lives in docs/ as ADRs.

Performance

A fair question is whether encoding and decoding every ID becomes a bottleneck at scale. In practice it doesn't, and the design is the reason why.

Both operations are pure in-memory integer arithmetic over a UUID's 16 raw bytes — no database round-trip, no I/O, no extension. Each is O(1): a fixed 128-bit number, always a ~22-character base62 tail. The informational benchmark (ADR-0009) times 1000 of each:

That's on the order of ~0.01 ms per ID — roughly json_encode-ing a small array, and orders of magnitude below a single database query. Serializing a 100-row API page adds around 1 ms of codec time. (Numbers are hardware-dependent; run the benchmark on your own target.)

Two design choices keep this off your hot paths:

There is no automatic regression gate — the benchmark reports rather than asserts (ADR-0009) so it never flakes across CI runners. If drift ever matters to you, that benchmark is the hook to add an env-gated threshold.

Caveats

Testing

The suite includes an informational benchmark (never gates the build); see Performance for what the numbers mean:

License

MIT.


All versions of laravel-public-ids with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/support Version ^12.0 || ^13.0
illuminate/database Version ^12.0 || ^13.0
illuminate/contracts Version ^12.0 || ^13.0
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 intrfce/laravel-public-ids contains the following files

Loading the files please wait ...