Php 在where子句laravel中使用Json属性
我有这个表Php 在where子句laravel中使用Json属性,php,mysql,json,database,laravel,Php,Mysql,Json,Database,Laravel,我有这个表折扣如果我有一个名为rules的列,它是一个json,里面有book数组,如下所示 表折扣: Column Rules: rules:"{\"books\":[1,2],others..} 现在我想通过Books表检查特定的图书是否包含在任何折扣->规则->图书中 我尝试的是: $discount = Discount:: whereJsonContains('rules->books',$this->id)->get(); 但这将返回空数组。数据类型必须匹配
折扣
如果我有一个名为rules
的列,它是一个json
,里面有book
数组,如下所示
表折扣:
Column Rules:
rules:"{\"books\":[1,2],others..}
现在我想通过Books表检查特定的图书是否包含在任何折扣->规则->图书中
我尝试的是:
$discount = Discount:: whereJsonContains('rules->books',$this->id)->get();
但这将返回空数组。数据类型必须匹配:
// [1, 2]
Discount::whereJsonContains('rules->books', 1) // Works.
Discount::whereJsonContains('rules->books', '1') // Doesn't work.
// ["1", "2"]
Discount::whereJsonContains('rules->books', '1') // Works.
Discount::whereJsonContains('rules->books', 1) // Doesn't work.
数据类型必须匹配:
// [1, 2]
Discount::whereJsonContains('rules->books', 1) // Works.
Discount::whereJsonContains('rules->books', '1') // Doesn't work.
// ["1", "2"]
Discount::whereJsonContains('rules->books', '1') // Works.
Discount::whereJsonContains('rules->books', 1) // Doesn't work.
希望你能在这里找到你的答案希望你能在这里找到你的答案我想数据类型是匹配的你能看到我的代码吗我用了$this->id我想这会像1而不是“1”对吗?只有一种方法可以检查它!使用dd(gettype($variable))
我认为数据类型匹配。你能看到我的代码吗?我使用了$this->id。我认为这会像1而不是“1”,对吗?只有一种方法可以检查它!使用dd(gettype($variable))