This actually worked fine. The issue was that my model had a one to many relationship with another table that used GUIDs that I had to apply this same logic to.
Solution - Auto update any models connecting to MSSQL by overriding model boot method
First, I created a scope to update the PDO connection:
<?php
namespace App\Api\V2\Model\Rule;
use Illuminate\Database\Eloquent\Scope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
class StringifyGuidRule implements Scope
{
/**
* Apply the scope to a given Eloquent query builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
*/
public function apply(Builder $builder, Model $model)
{
$hasPhp7GuidHelper = defined('\PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER');
if ($hasPhp7GuidHelper):
$model->getConnection()->getPdo()->setAttribute(\PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER, true);
endif;
}
}
Lastly, add the following to your model class:
/**
* The "booting" method of the model.
*
* @return void
*/
protected static function boot()
{
parent::boot();
//Any time this model is used, it will implement the StringifyGuidRule
static::addGlobalScope(new StringifyGuidRule());
}