Skip to content

Instantly share code, notes, and snippets.

@katalystsol
Last active July 22, 2019 20:48
Show Gist options
  • Save katalystsol/e770ce700d5e07c5b7f622cc991fa656 to your computer and use it in GitHub Desktop.
Save katalystsol/e770ce700d5e07c5b7f622cc991fa656 to your computer and use it in GitHub Desktop.
Laravel - copy char_36 column to binary_16 column
// For use with dyrynda/laravel-efficient-uuid && dyrynda/laravel-model-uuid
// Can be used for other Laravel conversions as well...
// Assumes you rename the uuid CHAR(36) column to uuid_save and add a uuid BINARY(16) column before running this via artisan tinker
// Replace App\Model with the appropriate model
$items = App\Model::all();
foreach ($items as $item) {
if (empty($item->uuid_save)) {
echo 'uuid_save is empty'.PHP_EOL;
continue;
}
$uuid = Ramsey\Uuid\Uuid::fromString($item->uuid_save);
echo $uuid->toString().' => '.$uuid->getBytes().PHP_EOL;
$item->uuid = $uuid->getBytes();
$item->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment