Laravel SQLite哪里有查询不起作用

时间:2014-03-10 14:50:44

标签: php sql laravel

我在我的Laravel应用程序中使用SQLite并尝试运行whereHas查询:

$payments = Payment::whereHas('payers', function($q){
    $q->where('user_id', '=', 1); 
})->get();

这将返回一个空结果,这是由于整数1被强制转换为字符串,由laravel / eloquent生成的结果查询证明:

select * from "payments" where (select count(*) from "payers" inner join "payer_payment" on "payers"."id" = "payer_payment"."payer_id" where "payer_payment"."payment_id" = "payments"."id" and "user_id" = 1) >= '1'

经过审核this github issue我尝试使用DB::raw,如此:

$payments = Payment::whereHas('payers', function($q){
      $q->where('user_id', '=', DB::raw(1)); 
})->get();

但没有改善。如何在不更改数据库驱动程序的情况下解决此问题?

1 个答案:

答案 0 :(得分:0)

$payments = Payment::whereHas('payers', function($q){
      $q->where('user_id', '=', 1); 
}, '>=', DB::raw(1))->get();