Last active
July 22, 2019 20:48
-
-
Save katalystsol/e770ce700d5e07c5b7f622cc991fa656 to your computer and use it in GitHub Desktop.
Laravel - copy char_36 column to binary_16 column
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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