3 回答
TA贡献1836条经验 获得超13个赞
如果我正确理解您的问题,您可以使用whereRaw()查询来构建您的条件,或者使用where()/构建单独的查询条件whereOr()。
使用whereRaw(),
\App\Model::whereRaw("price_1 <= ? AND threshold_1 <= ?", [$price_criteria, $quantity])
->orWhereRaw("price_2 <= ? AND threshold_2 <= ?", [$price_criteria, $quantity])
->orWhereRaw("price_3 <= ?", [$price_criteria]);
或者使用 Eloquent,
\App\Model::where(function($query) use ($quantity, $price_criteria) {
$query->where("price_1", "<=", $price_criteria)
->where("threshold_1", "<=", $quantity);
})->orWhere(function($query) use ($quantity, $price_criteria) {
$query->where("price_2", "<=", $price_criteria)
->where("threshold_2", "<=", $quantity);
})->orWhere(function($query) use ($quantity, $price_criteria) {
$query->where("price_3", "<=", $price_criteria)
});
TA贡献1779条经验 获得超6个赞
您应该$model像$quantity和一样传递参数$price_criteria(并添加一些标点符号:)):
\App\Model::where(function ($query) use ($quantity, $price_criteria, $model) {
if ($model->threshold_1 <= $quantity) {
$compare = $model->price_1;
} elseif ($model->threshold_2 <= $quantity) {
$compare = $model->price_2;
} else {
$compare = $model->price_3;
}
$query->where($compare, "<=", $price_criteria);
})->orWhere();
希望有帮助。
- 3 回答
- 0 关注
- 241 浏览
添加回答
举报