【发布时间】:2020-08-08 08:22:36
【问题描述】:
我正在尝试使用 eloquent 将关联数组传递给 where 子句,但出现错误。
这是我正在传递的示例
$where_array = [
'last_name' => 'Smith',
'first_name' => 'John'
];
$match = MyClass::where($where_array)->get();
这会返回如下错误:
“消息”:“SQLSTATE [42S22]:找不到列:1054 未知列 'where 子句'中的'{\"last_name\":\"Smith\",\"first_name\":\"John\"}' (SQL: select * from
my_classwhere{\"last_name\":\"Smith\",\"first_name\":\"John\"}为空且my_class.deleted_at为空限制 1)", “异常”:“照亮\数据库\查询异常”, “文件”:“/home/vagrant/code/unity/vendor/laravel/framework/src/Illuminate/Database/Connection.php”, “行”:669,
我不知道为什么它不使用数组或者为什么它检查它是否为空。是否有一些我不包括在内的库使这种格式有效?为什么它在查询中有 Object {} 括号?它是否在某处/以某种方式变成了一个对象?
【问题讨论】:
标签: arrays laravel eloquent where-clause associative-array