Lumen whereRaw with Prepared Statement Returns 无

Lumen whereRaw with Prepared Statement Returns Nothing

我正在尝试使用此查询从数据库中获取值

$vouchers = MerchantVoucher::where([
            'merchant_id' => $this->merchant->id,
            'code' => $voucherCode
        ])
        ->whereRaw("
            (
                (valid_from between '{$voucherValidFrom}' and '{$voucherValidTo}' ) || 
                (valid_to between '{$voucherValidFrom}' and '{$voucherValidTo}')
            )"
        )
        ->count();

通过此查询,我得到了预期的结果,returns 行数。 我尝试使用以下查询的准备语句优化查询

    $vouchers = MerchantVoucher::where([
        'merchant_id' => $this->merchant->id,
        'code' => $voucherCode
    ])
    ->whereRaw("
        ( 
            (valid_from between '?' and '?' ) || 
            (valid_to between '?' and '?' ) 
        )", 
        [
            $voucherValidFrom, 
            $voucherValidTo, 
            $voucherValidFrom, 
            $voucherValidTo
        ]
    )
    ->count();

当我使用这个查询时 returns 0.

有人对此有解释吗?提前谢谢你!

非PHP用户的原始Sql比较

 select count(*) from `merchant_vouchers` where (`merchant_id` = ? and `code` = ?) and 
                (
                    (valid_from between '2019-12-03 11:36:35' and '2019-12-10 11:36:35' ) || 
                    (valid_to between '2019-12-03 11:36:35' and '2019-12-10 11:36:35')
                ) and `merchant_vouchers`.`deleted_at` is null

Returns 1

  select count(*) from `merchant_vouchers` where (`merchant_id` = ? and `code` = ?) and 
                ( 
                    (valid_from between '?' and '?' ) || 
                    (valid_to between '?' and '?' ) 
                ) and 
                `merchant_vouchers`.`deleted_at` is null

Returns 0

使用的框架:Lumen

数据库:MySQL

您需要删除占位符周围的引号: valid_from between ? and ?