Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在where子句laravel中使用Json属性_Php_Mysql_Json_Database_Laravel - Fatal编程技术网

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))