Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jeyGey0719's avatar

Laravel 9 UUID

Hi,

I'm using Laravel 9.52.16.

I replaced the IDs with UUIDs on the users table.

In the migrations file:

$table->uuid('id')->primary();

In the model file:

use Illuminate\Database\Eloquent\Concerns\HasUuids;

use HasUuids;

I can get the list of all users

User::all();

But I can't get one user

User::findOrFail($id);

I have the following error:

"message": "SQLSTATE[22P02]: Invalid text representation: 7 ERREUR: syntaxe en entr\u00e9e invalide pour le type uuid : \u00ab 9aaea01a-ad56-401a-929a-479e01cffba \u00bb\nCONTEXT: param\u00e8tre de portail non nomm\u00e9 $1 = '...' (SQL: select * from "users" where "users"."id" = 9aaea01a-ad56-401a-929a-479e01cffba limit 1)",

what did I do wrong?

Thank you

0 likes
3 replies
Nakov's avatar
Nakov
Best Answer
Level 73

Make sure you add that the keyType is now string, and set the incrementing to false

public $incrementing = false;
protected $keyType = 'string';

the trait should already do that, but in case you are not running the version they introduced that.

jeyGey0719's avatar

it works than you.I didn't put the correct uuid...

Please or to participate in this conversation.