A package to extend Laravel migrations adding a more efficient storage of UUID fields in your database

3.0.1 2019-09-05 12:32 UTC



Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Total Downloads License


This package extends the default grammar file for the given MySQL connection adding an efficientUuid blueprint method that creates a binary(16) field.

As of 3.0, this package no longer overrides Laravel's default uuid method, but rather adds a separate efficientUuid field, due to compatibility issues with Laravel Telescope (#11).

Note: This package purposely does not use package discovery, as it makes changes to the MySQL schema file, which is something you should explicitly enable.

MySQL is the only supported connection type, only because I've no experience with other drivers. I welcome any pull requests to implement this functionality for other database drivers.

Note that doctrine/dbal does not appear to support changing existing uuid fields, and doing so would cause your existing values to be truncated in any event.

For more information, check out this post on storing and working with UUID in an optimised manner.

Using UUIDs in Laravel is made super simple in combination with laravel-model-uuid. Note that when using laravel-model-uuid, if you are not casting your UUIDs or calling the query builder directly, you'll need to use the getBytes method when setting the UUID on the database, otherwise your values will be truncated. Depending on your MySQL/MariaDB configuration, this may lead to application errors due to strict settings. See #1 for more information.

This package is installed via Composer. To install, run the following command.

composer require dyrynda/laravel-efficient-uuid

Register the service provider in your config/app.php configuration file:

'providers' => [

There is nothing special needed for this to function, simply declare a uuid column type in your migration files. I indexing the UUID column if you plan on querying against it, but would avoid making it the primary key.

Schema::create('posts', function (Blueprint $table) {

You will need to add a cast to your model when using laravel-model-uuid in order to correctly set and retrieve UUID from your MySQL database with binary fields.


namespace App;

use Illuminate\Database\Eloquent\Model;
use Dyrynda\Database\Support\GeneratesUuid;

class Post extends Model
    use GeneratesUuid;

    protected $casts = ['uuid' => 'uuid'];


If you are having general issues with this package, feel free to contact me on Twitter.

If you believe you have found an issue, please report it using the GitHub issue tracker, or better yet, fork the repository and submit a pull request.

If you're using this package, I'd love to hear your thoughts. Thanks!