简体   繁体   English

在 Laravel 中 UUID 不起作用的情况

[英]WhereIn condition with UUID not working in Laravel

My whereIn() condition using a UUID is not working for me in Laravel.我使用 UUID 的whereIn()条件在 Laravel 中对我不起作用。

public function skills($id)
{
    $skills = DB::table("industry_skill_sets")
        ->whereIn('industry_id', [$id])
        ->pluck("name", "id");
    
    print_r($skills);
    
    exit;
}

Here my id is the UUID separated by commas.这里我的 id 是用逗号分隔的 UUID。 So when I echo id, I am getting the following.因此,当我回显 id 时,我得到以下信息。

2b5e5507-7e01-45fe-b0ed-331135479061,7c816e0f-d6e2-489c-bdce-df064b3e99f9

When I use this variable in the WhereIn condition, It shows an error.当我在 WhereIn 条件中使用此变量时,它显示错误。

SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type uuid: "2b5e5507-7e01-45fe-b0ed-331135479061,7c816e0f-d6e2-489c-bdce-df064b3e99f9" SQLSTATE [22P02]:文本表示无效:7 错误:uuid 类型的输入语法无效:“2b5e5507-7e01-45fe-b0ed-331135479061,7c816e0f-d6e2-489c-bdce-df064b3e99f9”

I am using PostgreSQL as a database.我正在使用 PostgreSQL 作为数据库。

Need's to convert UUID to string需要将 UUID 转换为字符串

$skills = DB::table("industry_skill_sets")
                    ->whereIn('industry_id', explode(',',$id))
                    ->pluck("name","id");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM