php - Multiple Joins Laravel -


i need make 2 joins many conditionals where, have this

    $matchthese = [ 'suspended' => 0, 'status' => 1, 'approved' => 1 ];      $matchother = [ 'status' => 1, 'approved' => 0 ];      $deals = listsdeals::where( $matchthese )->where('stock', '>', 0)->orwhere( $matchother )->wheredate('end_date', '>', date('y-m-d'))->limit( 4 )->offset( 0 )->orderby( 'start_date' )->get();      $deals_lists = db::table('deals')                 ->join( 'list_has_deals', 'deals.id', '=', 'list_has_deals.deal_id'  )                 ->join( 'lists', 'list_has_deals.list_id', '=', 'lists.id' )                 ->paginate( 10 ); 

i need 1 unique query 2 vars, select deals 'wheres' in first var , later make joins, regards.

i think trick :

$query = listsdeals::where( $matchthese )->where('stock', '>', 0)->orwhere( $matchother )->wheredate('end_date', '>', date('y-m-d'))->limit( 4 )->offset( 0 )->orderby( 'start_date' );  $results = $query->join( 'list_has_deals', 'deals.id', '=', 'list_has_deals.deal_id'  )             ->join( 'lists', 'list_has_deals.list_id', '=', 'lists.id' )             ->paginate( 10 ); 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - VueJS2 and the Window Object - how to use? -