Download the PHP package slime-systems/eloquent-object-id without Composer

On this page you can find all versions of the php package slime-systems/eloquent-object-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 eloquent-object-id

Eloquent Object ID

MongoDB-style BSON's ObjectId for Eloquent and Laravel.

PHP Composer Packagist Version

✨ Features

📦 Installation

Install the package via Composer:

🤔 Why ObjectIDs?

Before diving into how to use ObjectIDs, it's important to understand why they are so useful. The ObjectID is a remarkable invention, offering significant benefits beyond a simple unique identifier.

The Basic

An ObjectID is a type of identifier, similar to Eloquent’s default incremental ID, used to reference a specific entity in the system.

ObjectIDs are powerful because they can be generated independently and in a decentralized manner by any trusted party. This eliminates the need to rely on a database or a centrally managed registry during ID creation. The generated IDs are designed to be sufficiently unique for most use cases, making collisions highly unlikely.

ObjectID is More Than a Generic ID

ObjectIDs inherently contain a timestamp. This property is extremely useful, for example, when performing time-based queries:

Suppose we want to count the cats registered in the past week:

If the ObjectID is set as the primary key, there is no need for a separate index to perform these time-based lookups. This query will be as optimized as one using an indexed created_at field, entirely avoiding a full table scan.

Essentially, ObjectIDs offer the querying power of timestamps directly within the identifier.

ObjectID is Also More Than Just a Timestamp

The ability to use the ID for chronological and offset-based queries is crucial for efficient pagination (known as keyset or cursor pagination).

A common, but highly unoptimized, way to paginate with an offset in Eloquent is:

The skip (or OFFSET) clause prevents database indexes from being fully utilized, leading to very slow queries on large datasets.

A better approach is to use the last known ID to fetch the next page, which works great with unique, chronologically ordered incremental IDs:

This query is fast because the where('id', '>', ...) condition can efficiently leverage the primary key index for lookup.

Attempting the same with only a timestamp field has a critical flaw:

While this could be fast if created_at is indexed, the logic is broken because the created_at timestamp is not guaranteed to be unique. If two entities are created in the same second, this query might incorrectly skip or miss records.

Guess what else is chronologically ordered and guaranteed to be unique?

That's right: ObjectID!

ObjectID is Also More Than an Incremental ID

A major limitation of traditional keyset (or cursor) pagination, when relying only on a sequential incremental ID, is the inability to jump to an arbitrary point in the dataset; users must navigate linearly from the start or from a known cursor.

This is where the ObjectID's embedded timestamp provides a unique advantage, transforming the approach to pagination by enabling chronological chunking and navigation.

The embedded time component allows developers to define predictable boundaries in the collection—like the start of a month or year—and generate an optimized cursor for that boundary without needing to query for a specific ID first.

This capability unlocks powerful UX patterns:

In essence, ObjectID provides the efficient scanning of incremental IDs while adding the random-access power of an embedded timestamp, making complex archival navigation simple and performant.

Various Ways to Utilize This Invention

As demonstrated, the ObjectID gives you the best of what both a timestamp and a unique, incremental ID have to offer. There is more than one way to utilize this powerful identifier. Have fun explore its full potential!

Note on Usage

In the following section, I will use ObjectID as a drop-in replacement for Eloquent's incremental ID.

While I do provide the helper function OI::setDefault, I personally do not believe this is the most effective or interesting way to utilize ObjectIDs.

If you bring forth the ObjectID's full potential, you'll likely find yourself not needing to use OI::setDefault at all.

🚀 Usage

Database Migration

Use the objectId column type in your migrations. This creates a binary column suitable for storing the ObjectId.

Model Setup

In your Eloquent model, cast the field using SlimeSystems\EloquentObjectId\ObjectIdCast.

Auto-generating IDs

Models can be configured to autogenerate an ObjectId. An example using the OI::setDefault helper in the booted method is provided below.

Accessing the ID from models

The ID will be automatically cast to SlimeSystems\ObjectId when retrieved from the database.

You can access all SlimeSystems\ObjectId methods documented at https://github.com/slime-systems/php-object-id.

Querying

OI::val() can be used to ensure that ObjectId is correctly formatted for compatibility with Eloquent queries.

✅ Tests

composer run test

or if you have containerd:

make test

📄 License

This library is open-sourced software licensed under the BSD-2-Clause license.


All versions of eloquent-object-id with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
illuminate/database Version >=10.0
illuminate/support Version >=10.0
slime-systems/object-id Version ^1.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 slime-systems/eloquent-object-id contains the following files

Loading the files please wait ...