Laravel 查询连接不为空

问题描述 投票:0回答:1

我在 MySQL 中有以下查询连接。

left join the_fields as tf on 
  tf.tf_kode = x.tf_kode
  and tf.is_payed is not null

我尝试像这样转换为 Laravel 查询生成器:

->leftJoin('the_fields as tf', function ($j) {
    $j->on('tf.tf_kode', '=', 'x.tf_kode');
    $j->on('tf.is_payed','!=', null);
})

但它显示错误

unknown column '' on clouse
。 请帮忙。谢谢!

mysql sql laravel left-join
1个回答
2
投票

您可以在

where
方法上使用任何
->on
过滤方法。

参见下面的代码:

->leftJoin('the_fields as tf', function ($j) {
    $j->on('tf.tf_kode', '=', 'x.tf_kode')->whereNotNull('tf.is_payed');
    // ->where(), ->whereBetween, ->whereIn() also works
});

希望这对您有帮助

© www.soinside.com 2019 - 2024. All rights reserved.