Relationships

Laravel Eloquent ORM Relationships

No operator matches the given name and argument types. You might need to add explicit type casts.

After I use the with() relationship function to get the related data on the elequent model and it shows the following error message.

Undefined function: 7 ERROR:  operator does not exist: character varying = integer
LINE 1: select * from "tag" where "tag"."id" in (0, 0, 0)
                                             ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.

Because I use the string type on my primary key but the default primary key type is integer. So we have to change the primary key type to solve this problem.

class TagModel extends Eloquent
{
    protected $table = 'tag';
    // Model Setting
    public $incrementing = false;
    protected $keyType = 'string';
}

Reference