PHPackages                             noolan/my-uuid - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. noolan/my-uuid

ActiveLibrary

noolan/my-uuid
==============

Easily use UUIDs as primary keys

011PHP

Since Feb 26Pushed 6y ago1 watchersCompare

[ Source](https://github.com/noolan/my-uuid)[ Packagist](https://packagist.org/packages/noolan/my-uuid)[ RSS](/packages/noolan-my-uuid/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

My UUID
=======

[](#my-uuid)

Simplifies using UUIDs in MySQL and Laravel

Install
-------

[](#install)

```
composer require noolan/my-uuid
```

Configure
---------

[](#configure)

### Copy Config File

[](#copy-config-file)

```
php artisan vendor:publish --provider Noolan\\MyUuid\\Service
```

The settings for this package can now be edited in `config/myuuid.php`.

### Available Settings

[](#available-settings)

KeyTypeDefaultDescription`mysql_8`Boolean`true`MySQL 8 adds two new functions, `UUID_TO_BIN` and `BIN_TO_UUID` that simplify working with UUIDs.
If `mysql_8` is true, those new functions will be used instead of the mashup of `HEX`, `UNHEX`, and `REPLACE` that is otherwise required.
If you are unsure which version of MySQL you have you can run the `php artisan myuuid:version` command detailed below.`connection`String`''` (empty string)The name of the database connection to use as defined in your `config/database.php` file.
An empty string will result in your default connection being used.### Checking Configuration

[](#checking-configuration)

There are two Artisan commands included with this package that help with configuration; `version` and `check`.

CommandArgumentsDescriptionExample`myuuid:version`(none)Outputs the MySQL version of the configured connection.`php artisan myuuid:version``myuuid:check`(none)Checks the current configuration against the database to see if there are issues.`php artisan myuuid:check`Usage
-----

[](#usage)

### Instantiation

[](#instantiation)

All the functionality is accessed through the `MyUuid` facade.

```
use MyUuid;
/* ... */
public function doAThing()
{
    $myUuid = MyUuid::alter('examples');
    /* ... */
}
```

### Chaining

[](#chaining)

Most methods on the MyUuid class return the object so methods can be chained.

```
$myUuid->addColumn('uuid', 'blob', 16)
$myUuid->addColumn('parent_id', 'varbinary', 36)
$myUuid->addIndex();

$myUuid->run();

// Can be re-written as:

$myUuid->addColumn('uuid', 'blob', 16)
       ->addColumn('parent_id', 'varbinary', 36)->addIndex()
       ->run();
```

**Note:* If a non-column function is called without a column name parameter, MyUuid uses the last added column as a default.*

### Convenience Functions

[](#convenience-functions)

There are several functions that make it easy to perform common tasks as long as you don't need to deviate from the default parameters.

```
/* Add an auto-populating, 16 byte, binary column named 'id'
   and use it as the table's primary key */

$myUuid->addPrimaryUuid('id');

// is equivalent to:

$myUuid->addColumn('id', 'binary', 16)
       ->addIndex('primary')
       ->addTrigger();
```

### Executing Queries and Rolling Back Migrations

[](#executing-queries-and-rolling-back-migrations)

Columns and indexes created with MyUuid can be dropped with Laravel's Schema builder. The only thing you have to manually drop is triggers.

```
// removes auto-population trigger attached to the 'id' column
$myUuid->dropTrigger('id')->run();
```

### API

[](#api)

#### Uuid Methods

[](#uuid-methods)

 **alter**  **(***String* $table**)**
 returns: new *UuidSchema*  **getVersion**  ()
 returns: *String* MySql version  **getTrustFunctionCreatorsSetting**  ()
 returns: *Boolean* on #### UuidSchema Methods

[](#uuidschema-methods)

 **addColumn**  (*String* $name, \[*String* $type, *Integer* $length, *String* $virtualTarget\])
 returns: *UuidSchema* self  **addIndex**  (\[*String* $type, *String* $column, *String* $cname, *Integer* $length\])
 returns: *UuidSchema* self  **addTrigger**  (\[*String* $column\])
 returns: *UuidSchema* self  **dropTrigger**  (*String* $column) returns: *UuidSchema* self  **run**  () returns: null #### UuidSchema Convenience Methods

[](#uuidschema-convenience-methods)

 **addPrimaryUuid**  (*String* $name)
 returns: *UuidSchema* self  **addAutoUuid**  (*String* $name)
 returns: *UuidSchema* self  **addFriendlyUuid**  (*String* $name, *String* $target)
 returns: *UuidSchema* self  **withFriendly**  (*String* $target)
 returns: *UuidSchema* self  **addIndexedUuid**  (*String* $name)
 returns: *UuidSchema* self  **index**  (\[*String* $type\])
 returns: *UuidSchema* self  **addForeignUuid**  (*String* $name)
 returns: *UuidSchema* self ### Example

[](#example)

```
