Query builder whereIn AND whereNotIn

Posted 4 months ago by Virtualmix

Hello All,

I was hoping to get some help with the following query builder. I would like to return a random listing that exists in my 'quotes' table but does not exists in my 'orders' table.

    $listing = App\Listing::whereIn('id', function ($p) {
        $p->select('listing_id')->from('quotes');
    }, 'AND')
    ->whereNotIn('id', function ($q) {
        $q->select('listing_id')->from('orders');
    })
    ->get()->random();

I've spent hours trying to get this query working... It's close but still returns listings that already exists in the orders table...

Any idea what I'm doing wrong?

Please sign in or create an account to participate in this conversation.