【发布时间】:2018-02-13 18:20:45
【问题描述】:
所以在 Laravel 5 中有一个方便的东西,叫做 JSON Where Clauses,它使用 MySQL 存储和获取存储在列中的 JSON 的新功能:
User::where('meta->colors', 'red')->get()
将返回所有行,其中meta 列中的colors 将设置为red。
现在假设colors 不是字符串,而是包含多种颜色的数组 (colors => ['red', 'blue', 'green'])。
什么是检索所有行的有效方法,其中colors 包含例如值red?
【问题讨论】:
-
你的意思是 $x = ['red', 'blue', 'green'];或 $x = (colors => ['red', 'blue', 'green']) ?
-
你试过WhereIn条件???
-
澄清:用户有一个属性/列,假设它被称为
meta,其中包含以下JSON:{ "colors": ["red", "blue", "green"] }我想检索它,如果colors包含值red.
标签: php mysql json laravel eloquent