Apa metode permintaan dari dua tabel dengan kondisi di Laravel

$query = Invoice_Details::query()-> with('invoice');
          
        
         if($request->invoice_type==1){

              $query->whereRelation('invoice','Invoice_type','=' ,1);
           }

    $Details = $query->get();

    return $Details -> sum('quantity');
SAMER SAEID