如何在数据库列中获取数组? Laravel

问题描述 投票:0回答:1

我想在数据库中获取数组,它可以在数据库查询中工作(我的数据库我使用postgrest),但是在我的项目laravel中不起作用。错误消息->未定义列:7错误:列sample1.text [1]不存在

table sample1
___________________________________
|   id | name |      text[]        |
|------+------+--------------------|
|    1 |   aa | {xxx1,xxx2,xxx3}   |
|    2 |   bb | {xxx1,xxx2,xxx3}   |
|    3 |   cc | {xxx1,xxx2,xxx3}   |
|______|______|____________________|

我需要价值

{ 
  xxx1,
  xxx1,
  xxx1
}

我的代码

   $search = DB::table("sample1")->select(array( 'sample1.text[1]'))->get();

    return response()->json($search);

在我的数据库查询中有效

SELECT "NSO_STAT_GIS"."BND_SET_STAT_TABLE"."MAPTB_CAT_SL_ID"[1] FROM "NSO_STAT_GIS"."BND_SET_STAT_TABLE"
php laravel laravel-5.8 postgrest
1个回答
0
投票
$textsJson = DB::table("sample1")->select('text')->get();
$textArray = json_decode($textsJson);

https://laravel.com/docs/5.8/queries#selects

© www.soinside.com 2019 - 2024. All rights reserved.