Download the PHP package spatie/laravel-binary-uuid without Composer

On this page you can find all versions of the php package spatie/laravel-binary-uuid. 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-binary-uuid

THIS PACKAGE IS NOT MAINTAINED ANYMORE

Alternatives: https://github.com/michaeldyrynda/laravel-efficient-uuid & https://github.com/michaeldyrynda/laravel-model-uuid

Using optimised binary UUIDs in Laravel

Latest Version on Packagist Build Status Code coverage Quality Score StyleCI Total Downloads

Using a regular uuid as a primary key is guaranteed to be slow.

This package solves the performance problem by storing slightly tweaked binary versions of the uuid. You can read more about the storing mechanism here: http://mysqlserverteam.com/storing-uuid-values-in-mysql-tables/.

The package can generate optimized versions of the uuid. It also provides handy model scopes to easily retrieve models that use binary uuids.

Want to test the perfomance improvements on your system? No problem, we've included benchmarks.

The package currently only supports MySQL and SQLite.

Installation

You can install the package via Composer:

Usage

To let a model make use of optimised UUIDs, you must add a uuid field as the primary field in the table.

To get your model to work with the encoded UUID (i.e. to use uuid as a primary key), you must let your model use the Spatie\BinaryUuid\HasBinaryUuid trait.

If don't like the primary key named uuid you can manually specify the getKeyName method. Don't forget set $incrementing to false.

If you try converting your model to JSON with binary attributes, you will see errors. By declaring your binary attributes in $uuidAttributes on your model, you will tell the package to cast those UUID's to text whenever they are converted to array. Also, this adds a dynamic accessor for each of the uuid attributes.

In your JSON you will see uuid and country_uuid in their textual representation. If you're also making use of composite primary keys, the above works well enough too. Just include your keys in the $uuids array or override the getKeyName() method on your model and return your composite primary keys as an array of keys. You can also customize the UUID text attribute suffix name. In the code above, instead of '_text' it's '_str'.

The $uuids array in your model defines fields that will be converted to uuid strings when retrieved and converted to binary when written to the database. You do not need to define these fields in the $casts array in your model.

A note on the uuid blueprint method

Laravel currently does not allow adding new blueprint methods which can be used out of the box. Because of this, we decided to override the uuid behaviour which will create a BINARY column instead of a CHAR(36) column.

There are some cases in which Laravel's generated code will also use uuid, but does not support our binary implementation. An example are database notifications. To make those work, you'll have to change the migration of those notifications to use CHAR(36).

Creating a model

The UUID of a model will automatically be generated upon save.

Getting a human-readable UUID

UUIDs are only stored as binary in the database. You can however use a textual version for eg. URL generation.

If you want to set a specific UUID before creating a model, that's also possible.

It's unlikely though that you'd ever want to do this.

Querying the model

The most optimal way to query the database:

The withUuid scope will automatically encode the UUID string to query the database. The manual approach would be something like this.

You can also query for multiple UUIDs using the withUuid scope.

Note: Version 1.3.0 added simplified syntax for finding data using a uuid string.

Version 1.3.0 query for multiple UUIDs.

Querying relations

You can also use the withUuid scope to query relation fields by specifying a field to query.

Running the benchmarks

The package contains benchmarks that prove storing uuids in a tweaked binary form is really more performant.

Before running the tests you should set up a MySQL database and specify the connection configuration in phpunit.xml.dist.

To run the tests issue this command.

Running the benchmarks can take several minutes. You'll have time for several cups of coffee!

While the test are running average results are outputted in the terminal. After the tests are complete you'll find individual query stats as CSV files in the test folder.

You may use this data to further investigate the performance of UUIDs in your local machine.

Here are some results for the benchmarks running on our machine.

A comparison of the normal ID, binary UUID and optimised UUID approach. Optimised UUIDs outperform all other on larger datasets.

Testing

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

Support us

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-binary-uuid with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1
illuminate/queue Version ~5.5.28|~5.6.0|~5.7.0
ramsey/uuid Version ^3.7
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 spatie/laravel-binary-uuid contains the following files

Loading the files please wait ....