gpt4 book ai didi

mysql - Laravel 如何将 2 个值与一个字段匹配

转载 作者:行者123 更新时间:2023-11-29 12:13:48 25 4
gpt4 key购买 nike

目前我面临的问题是我使用 orWhere 来获得正确的结果,但没有获得准确的结果。我想要获得字段仅包含付费灵活

的结果

例如状态

  • 付费
  • 付费
  • 灵活
  • 付费
  • 付费
  • 灵活

但是通过这个查询,我也得到了UnPaid,但我不想要UnPaid结果

$orders = Order::with('orderfiles','orderStatus','orderDelivery','flexibleDelivery')->whereHas('payment', function ($query) {
$query->where("status","=",'Paid')->orwhere('status' ,'=', 'Flexible');
})->whereBetween("tbl_orders.order_date", $range)->where('domain_id','=',$domain_id)->orderBy('order_date','asc')->paginate();
return View('admin.all_orders')
->with('orders',$orders)->with('title','Results - Paid and Flexible Orders')->with('logoNum',$domain_id);

SQL

Array
(
[0] => select count(*) as aggregate from `tbl_orders` where (select count(*) from `tbl_payments` where `tbl_payments`.`order_id` = `tbl_orders`.`order_id` and `status` = ? or `status` = ?) >= 1 and `tbl_orders`.`order_date` between ? and ? and `domain_id` = ?
[1] => Array
(
[0] => Paid
[1] => Flexible
[2] => 2015-01-01
[3] => 2015-05-31
[4] => 18
)

[2] => 7233.41
[3] => mysql
)

最佳答案

我知道您已经接受了答案,但这确实不是最好的方法。您可以使用 Laravel 的 whereIn 查询方法:

$query->whereIn('status', ['Paid', 'Flexible']);

第一个参数是列名称,第二个参数是要匹配的值的数组。

关于mysql - Laravel 如何将 2 个值与一个字段匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30208166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com