Skip to content
Advertisement

Laravel query join on not null

I have the following query join in MySQL.

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

I tried to convert to laravel query builder like this:

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

But it shows the error unknown column '' on clouse. Please help. Thanks!

Advertisement

Answer

->on method arguments are columns and operators, You cant pass where condition in it.

You can use this:

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

Hope this helps you

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement