I am selecting model instances from a table that uses UUIDs as primary keys. That works fine when I pass a string into find() to fetch the model instance.
MyModel::find('18af8e5b-97ce-b26d-9037-4e6e0fb82f20');
// Returns my instance.
MyModel::find('18');
// Rightly returns null.
MyModel::find(18);
// Returns my model instance again. Yikes!
It seems that eloquent is passing the data type provided into the query, and MySQL is doing some casting (a-la-PHP!) to return a row that it should not return.
How can I set up the model to make sure find() will always do a string search on the primary key, regardless of what has been passed in?
As a bonus, this returns the first row it finds:
MyModel::find(0);
No, eloquent, naughty! How do I whip it into shape? None of the following on the model work:
public $incrementing = false;
protected $casts = [
'id' => 'string',
];
protected $keyType = 'string';
So is my only option to override static find()?