[ -6ren">
gpt4 book ai didi

php - 如何在php(laravel)中的mysql的select语句中添加数组?

转载 作者:行者123 更新时间:2023-11-29 17:59:48 25 4
gpt4 key购买 nike

我试图在 laravel 的 select 语句中添加数组,这是示例数据,请检查以下代码片段,

    $message =["messages"=>[ 
["attachment"=>
["type"=>"template","payload"=>
["template_type"=>"list","top_element_style"=>"large","elements"=>
[
["title"=>"test","image_url"=> "https://cdn-images-1.medium.com/max/375/0*sepg7sXXe3zcmGvZ.png","subtitle"=>"Soft white cotton t-shirt is back in style","buttons" =>
[
["type"=>"web_url","url"=>"https://petersapparel.parseapp.com/buy_item?item_id=101","title"=>"buy item"]
]
]
,
["title"=>"test","image_url"=> "https://cdn-images-1.medium.com/max/375/0*sepg7sXXe3zcmGvZ.png","subtitle"=>"Soft white cotton t-shirt is back in style","buttons" =>
[
["type"=>"web_url","url"=>"https://petersapparel.parseapp.com/buy_item?item_id=101","title"=>"buy item"]]
]

]
]

]
]
]
];

当我从 Laravel 中的数据库中提取数据时,我只能做直到字幕,我不能做按钮部分

  ["type"=>"web_url","url"=>"https://petersapparel.parseapp.com/buy_item?item_id=101","title"=>"buy item"]

,这是我尝试过的,

    $message =["messages"=>[ 
["attachment"=>
["type"=>"template","payload"=>
["template_type"=>"list","top_element_style"=>"large","elements"=>
[
Fabric::orderBy('id', 'DESC')->where('title', 'LIKE', "%$search_term%")
->select('title','postdate as image_url',"company_name as subtitle"
)->get()
]
]

]
]
]
];

我还有每个按钮数组字段的另一个字段,不知道如何添加到选择语句中。任何帮助将不胜感激。

最佳答案

Eloquent 模型上的 get 方法返回一个集合,但看起来您正在寻找一个数组。

所以只需修改您的代码,如下所示:

Fabric::orderBy('id', 'DESC')->where('title', 'LIKE', "%$search_term%")
->select('title','postdate as image_url',"company_name as subtitle")
->get()->toArray();

关于php - 如何在php(laravel)中的mysql的select语句中添加数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48484896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com