Hi guys,
I am developing a project where the requesting company asked for the table identifiers to be uuid (as much as I did not agree), so in my models I configured it like this
/ **
聽 * Indicates if the IDs are auto-incrementing.
聽 *
聽 * @var bool
聽 * /
public $ incrementing = false;
/ **
聽 * Boot uuid.
聽 *
聽 * @return void
聽 * /
public static function bootUuid ()
{
聽聽聽聽 static :: creating (function ($ model) {
聽聽聽聽聽聽聽聽 $ model -> {$ model-> getKeyName ()} = (string) Str :: uuid ();
聽聽聽聽 });
}
This worked until version 5.7.13, but now in 5.7.14 is giving the error
SQLSTATE [42883]: Undefined function: 7 ERROR: operator does not exist: uuid = integer
How can I get around this?
Thank you
I just tried the same, but using a mysql database instead of PostgreSql, and it ran successfully.
A quick google resulted in the following page:
https://stackoverflow.com/questions/46433459/postgres-select-where-the-where-is-uuid-or-string
In the stackoverflow page they stated casting the column to uuid helped: uuid::uuid
@CrixuAMG,
But because in the version of laravel 5.7.13 it works normally and in version 5.7.14 it does not? Would it be a database error?
Also, there's a note in the documentation:
Primary Keys
[鈥 If your primary key is not an integer, you should set the protected $keyType property on your model to string.
@bonzai, wow!
Thank you very much guy.
Most helpful comment
26582
Also, there's a note in the documentation:
https://laravel.com/docs/5.7/eloquent#defining-models