Created
June 17, 2017 16:31
-
-
Save marabesi/39e67f05bcfb07dd2a4afb00e79e9d96 to your computer and use it in GitHub Desktop.
Query builder - is it possible to test it?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Repositories; | |
use DB | |
class MyRepository | |
{ | |
public function getAllAmountsByProduct(array $revenueTable, $sRevColumns, $sCompanyID) | |
{ | |
$firstTable = 'rev_rec_' . $revenueTable[0]; | |
$queryBuilder = DB::table("$firstTable") | |
->join('deal_product', 'deal_product.id', '=', "$firstTable.deal_product_id") | |
->join('products', "deal_product.product_id", '=', 'products.id'); | |
for ($i = 1; $i < count($revenueTable); $i++) { | |
$queryBuilder->join("rev_rec_$revenueTable[$i]", "$firstTable.id", '=', "rev_rec_$revenueTable[$i]" . '.id'); | |
} | |
$queryBuilder->select(DB::raw("products.id, products.name, $sRevColumns")) | |
->where("$firstTable.co_id", '=', $sCompanyID) | |
->groupBy('products.id'); | |
return $queryBuilder->get(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment