I've built a new Laravel 5.3 application, and in my tables I'm using postgres UUID
as the primary and foreign keys.
In defining the Laravel models, I created the relationships normally. However, it appears that Laravel's ORM isn't translating the request properly:
PHP Warning: Uncaught exception 'PDOException' with message 'SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for uuid: "0"'
I've searched the laravel docs but haven't found anything to explain how to use UUIDs as keys. Is there some additional configuration I need to do?
The reason for this is you need to tell the model that the key does not auto-increment.
class User extends Authenticatable {
use Notifiable, HasRole, SoftDeletes;
public $incrementing = false;
// User code
Once you have set this, Eloquent then knows that it is not looking for an integer and will stop returning "0" when querying the model.
You can follow a tutorial on using UUID's with laravel here: https://garrettstjohn.com/article/using-uuids-laravel-eloquent-orm/