Why does Eloquent (in Laravel) cast my varchar uuid primary key to an integer resulting in errors?
In order for this to work I had to manually override the casting type of the primary key in my model.
protected $casts = [
'id' => 'string'
];
For those coming here later. You can override the $keyType
variable in your model with the string type:
protected $keyType = 'string';
I looked into the \Illuminate\Database\Eloquent\Model
class and found that the most effective way is to set $incrementing = false
in your Model.
In my tests both creating and retrieving the model worked as intended.
This is the snipped with the PHP docs comments.
/**
* Indicates if the IDs are auto-incrementing.
*
* @var bool
*/
public $incrementing = false;