ENTITY_ID
。当我使用whewhasmorph时,我会遇到一个类型错误,因为用户表ID是bigint
示例:
$query->whereHas('user', function (Builder $query) use ($dto) {
$query->whereRaw("id = ?", [$dto->sender])
->orWhereRaw("username = ?", [$dto->sender]);
});
$query->whereHasMorph('entity', [EntityTypeEnum::USER->value], function (Builder $query) use ($userId) {
$query->whereRaw("id = ?", [$userId]);
});
return;
输出错误:
SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: character varying = bigint\n
LINE 1: ...users" where "payment"."transactions"."entity_id" = "account...\n
^\n
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
在这种情况下该怎么做,如何在不使用RAWSQL
的情况下解决类型中的错误 chat gpt不要给我任何工作解决方案
出现您的问题是因为在您的
transactions
表中,entity_id
VARCHAR
id
列是类型
users
。 PostgreSQL在
BIGINT
子句中比较它们时不会自动施放
VARCHAR
。