Skip to content

Instantly share code, notes, and snippets.

@marabesi
Created June 17, 2017 16:31
Show Gist options
  • Save marabesi/39e67f05bcfb07dd2a4afb00e79e9d96 to your computer and use it in GitHub Desktop.
Save marabesi/39e67f05bcfb07dd2a4afb00e79e9d96 to your computer and use it in GitHub Desktop.
Query builder - is it possible to test it?
<?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