Download the PHP package kenzal/mysql-binary-uuids without Composer

On this page you can find all versions of the php package kenzal/mysql-binary-uuids. 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 mysql-binary-uuids

Laravel MySQL Binary UUIDs

Store UUIDs and ULIDs as efficient binary(16) columns in MySQL instead of char(36) or char(26), saving storage space and improving index performance.

Tests Code Style PHP Version Laravel Version Packagist Version

Table of Contents

Why Use Binary Storage?

Storing UUIDs and ULIDs as binary data provides significant benefits:

Storage Comparison

Type String Storage Binary Storage Savings
UUID 36 bytes (char) 16 bytes (binary) 56% reduction
ULID 26 bytes (char) 16 bytes (binary) 38% reduction

Requirements

Compatibility Matrix

Laravel PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
12.x
13.x

Installation

Install via Composer:

The service provider will be automatically registered.

[!CAUTION] Upgrading from String (char) UUIDs

If you're migrating an existing project from char(36) or varchar(36) UUIDs to binary(16):

  1. Install this package
  2. Update your models to use the traits or casts
  3. Create migrations to convert columns
  4. Plan for a breaking schema change — test thoroughly in staging first

Key query change: Binary(16) columns store UUIDs/ULIDs as raw bytes, not human-readable strings. When querying, you must pass UuidInterface or Ulid objects — raw strings will not be automatically converted to binary at the connection level:

Route-model binding is handled automatically — string UUIDs/ULIDs from URLs are converted to objects before querying.

Features

✨ Automatic Schema Support

UUIDs are automatically stored as binary(16) when using Laravel's schema builder:

🔄 Eloquent Casts

Cast binary UUID/ULID columns to native Laravel objects:

🎯 Model Traits

Drop-in replacements for Laravel's HasUuids and HasUlids traits:

🛠️ Blueprint Macros

Additional Blueprint methods for ULID columns:

Usage

Basic Usage with Casts

Using Model Traits

The HasBinaryUuids and HasBinaryUlids traits provide automatic ID generation:

Using ULIDs

Custom Unique ID Columns

By default, traits apply to the id column. Customize via the uuidColumns() or ulidColumns() methods:

Custom UUID/ULID Types

You can specify custom UUID/ULID subclasses for specific columns using string keys. This is useful when you need to extend UUIDs with domain-specific behavior.

First, create your custom UUID class:

Then reference it in your model:

The same pattern works with ExtensibleUlid and ulidColumns().

Using Directly in casts()

Since ExtensibleUuid and ExtensibleUlid implement Laravel's Castable interface, you can also use them directly in the casts() array without traits:

Using Both UUID and ULID Columns

A model can have both UUID and ULID columns by using one trait for auto-generation and explicit casts for others:

Migration Examples

Creating Tables with UUIDs

Creating Tables with ULIDs

Nullable UUID/ULID Columns

Working with Existing Data

If you're migrating from string-based UUIDs, create a migration to convert:

Route Model Binding

Binary UUID/ULID columns work seamlessly with Laravel's implicit and explicit route-model binding. The traits handle the conversion automatically — string UUIDs/ULIDs from URLs are converted to UuidInterface/Ulid objects before querying, and the connection handles the binary conversion.

Implicit Binding

With traits, no additional configuration is needed:

Explicit Binding

Works with casts too — register the binding in AppServiceProvider:

Or use Laravel's getRouteKeyName() on the model.

Custom Route Key Names

Override getRouteKeyName() to bind on a different binary UUID/ULID column:

API Reference

Casts

BinaryUuid

Casts binary(16) columns to Ramsey\Uuid\UuidInterface objects.

Methods:

BinaryUlid

Casts binary(16) columns to Symfony\Component\Uid\Ulid objects.

Methods:

Traits

HasBinaryUuids

Provides automatic UUID v7 generation with binary storage.

Features:

Methods:

HasBinaryUlids

Provides automatic ULID generation with binary storage.

Features:

Methods:

Blueprint Macros

binaryUlid(string $column = 'ulid')

Create a binary(16) ULID column.

foreignBinaryUlid(string $column)

Create a foreign key column for referencing a binary ULID.

Testing

The package includes a comprehensive test suite:

Run specific test suites:

Performance Considerations

Query Performance

Binary UUIDs maintain excellent query performance. When querying, pass UuidInterface or Ulid objects — the connection automatically converts them to binary:

Index Recommendations

For optimal performance:

  1. Always index UUID/ULID foreign keys:

  2. Use UUID v7 or ULIDs for time-ordered data:

    • Both have time-based sorting
    • Reduces index fragmentation
    • Better for clustered indexes
  3. Consider composite indexes:

Compatibility

UUID Versions

This package works with all UUID versions:

The HasBinaryUuids trait generates UUID v7 by default for better database performance.

ULID Format

ULIDs are 128-bit identifiers:

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Development Setup

Local Testing Configuration

Copy phpunit.xml.dist to phpunit.xml and customize for your local environment:

Then edit phpunit.xml with your local MySQL credentials:

Note: phpunit.xml is gitignored so your local credentials won't be committed.

Running Tests

Or run specific test suites:

Code Style

This package uses Laravel Pint for code formatting. Before submitting a PR:

Make sure all tests pass and code style checks pass before submitting a PR.

License

This package is open-sourced software licensed under the MIT license.

Credits

Support

Changelog

See CHANGELOG.md for version history.


Made with ❤️ for the Laravel community


All versions of mysql-binary-uuids with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/database 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 kenzal/mysql-binary-uuids contains the following files

Loading the files please wait ...