Home > Mobile >  How to call model function in query builder
How to call model function in query builder

Time:12-06

Function From Customer to Order & Function check active order

Query
How to get customers where doesnt have relation in Order Models and customers where have relation in Order but the Order was inactive ??

Get Customer where doesnt have relation in order and customer where have relation in Order but Order state was inactive/expired

CodePudding user response:

Try This

Customer::with('orders')->whereDoesntHave('orders')->orWhereHas('orders', function($query){
        $query->select('orders.state')
            ->from('orders')
            ->whereColumn('orders.customer_id', 'customers.id');
    }, 'expired')->get();
  • Related