Search code examples
sql-serverlaravelencodingvagrant

Laravel Homestead Changing UUID


We did not start initially using Laravel Homestead, but are working on getting homestead set up to make version control easier.

Everything seems to be working fine other than my UUIDs are being encoded strangely.

Production Environment:

Illuminate\Support\Collection {#681 ▼
    `#items: array:148 [▼
        0 => {#685 ▼
            +"MyId": "D281ACC2-1F3D-470E-9CBD-26957763F197"
            +"TheirId": "43499884-2C18-4591-BDF1-D994DDDD1314"

Local Environment:

Illuminate\Support\Collection {#681 ▼
    `#items: array:148 [▼
        0 => {#685 ▼
            +"MyId": b"ê1÷ÞhÙéDÉï\x01³ú'┌á"
            +"TheirId": b"pE;¿_J]EòØö▀i#8¾"

Codebases are identical. The only thing I can think of is the Vagrant box using a different sqlsrv driver, so I have installed pdo_sqlsrv but it has not fixed the issue.

Any ideas?


Solution

  • I found what seems to be a fix. I appended the options array.

        'sqlsrv' => [
            'driver' => 'sqlsrv',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '1433'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
            'options'  => [
                // Used for GUIDs
                PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER => true,
            ],
        ],
    

    Answer was stolen from @tom-sinclair https://github.com/laravel/homestead/issues/823#issuecomment-391619635