【发布时间】:2013-06-19 20:00:22
【问题描述】:
我正在尝试将查询字符串解析为涉及“或”语句的 Eloquent。 这是应用了其他过滤器等的更大功能的一部分,但我想make an or_where group。
我的困惑来自于闭包......以及如何确保传递正确的值。如果我按照下面的代码进行操作,则说明闭包的参数错误,否则我无法授予它访问 $or_list 变量的权限。
($thing_query 是在此功能和其他功能过程中构建的查询。)
elseif (strstr($column, 'or|')){
//in format or|=tablename-id=240,tablename-id=8
$or_list = explode(',', $value);
var_dump(explode(',', $value));
$thing_query->where(function($q, $or_list)
{
$count = 0;
foreach ($or_list as $or) {
$arr = explode('=', $or);
$col = $arr[0];
$val = $arr[1];
$col = str_replace('-', '.', $col);
if($count == 0){
$q->where($col, '=', $val);
} else {
$q->or_where($col, '=', $val);
}
$count++;
}
});
}
【问题讨论】:
标签: php closures laravel eloquent