src/Big.php
/**
     * Bind data to sql query and replace table name with the correct dataset and project name
     *
     * @param object(Illuminate\Database\Eloquent\Builder) $query with ? for bind data
     * @param array $tables (table name used in the query) for replacing with the correct name project+dataset+table
     * @param int $num (numbert of items in pagination) use 0 for illimited
	 * @param int $page (page parameter for pagination)
	 * @param array $arrLikeFields (fields with "like queries" to replace with lower case)
	 * 
     * @return mixed
	 *
	 * Example:
	 *  $query = Product::where("sku","=",$sku);
	 *	$sql = $big->bindQuery($query, array("products"));
	 *	$results = Big::unflipModel(new Product(), $big->run($sql));
     */
Bind data to sql query and replace table name with the correct dataset and project name
@param object(Illuminate\Database\Eloquent\Builder) $query with . for bind data
@param array $tables (table name used in the query) for replacing with the correct name project+dataset+table
@param int $num (numbert of items in pagination) use 0 for illimited
@param int $page (page parameter for pagination)
@param array $arrLikeFields (fields with "like queries" to replace with lower case)

@return mixed


Bind data to sql query and replace table name with the correct dataset and project name @param object ( Illuminate \ Database \ Eloquent \ Builder ) $query with . for bind data @param array $tables ( table name used in the query ) for replacing with the correct name project + dataset + table @param int $num ( numbert of items in pagination ) use 0 for illimited @param int $page ( page parameter for pagination ) @param array $arrLikeFields ( fields with " like queries " to replace with lower case ) @return mixed
public function bindQuery($query, $tables, $num=15, $page = 1, $arrLikeFields =[]){
		$sql = $query->toSql();
		$bindDataArr =$query->getBindings();
		foreach($bindDataArr as $binding)
		{
			$value = is_numeric($binding) ? $binding : "'".$binding."'";
			$sql = preg_replace('/\?/', $value, $sql, 1);
		}
		foreach ($arrLikeFields as $field){
			$sql = str_ireplace("`".$field."` LIKE","LOWER(`".$field."`) LIKE",$sql);
		}
		$dataset = $dataset ?? $this->defaultDataset;
		foreach ($tables as $table){
			$sql = str_ireplace("`".$table."`","`".config('prologue-big.big.project_id').".".$dataset.".".$table."`",$sql);
		}
		if (!isset($page)){
			$page = 1;
		}
		if ($num>0){
			$sql .= " limit ".$num." offset ".($num*($page-1));
		}
		$sql = str_ireplace("`RAND()`","RAND()",$sql);
		return $sql;
	}
public function bindQuery ( $ query , $ tables , $ num = 15 , $ page = 1 , $ arrLikeFields = [ ] ) { $ sql = $ query -> toSql ( ) ; $ bindDataArr = $ query -> getBindings ( ) ; foreach ( $ bindDataArr as $ binding ) { $ value = is_numeric ( $ binding ) ? $ binding : " ' " . $ binding . " ' " ; $ sql = preg_replace ( '/\?/' , $ value , $ sql , 1 ) ; } foreach ( $ arrLikeFields as $ field ) { $ sql = str_ireplace ( " ` " . $ field . " ` LIKE " , " LOWER(` " . $ field . " `) LIKE " , $ sql ) ; } $ dataset = $ dataset ?? $ this -> defaultDataset ; foreach ( $ tables as $ table ) { $ sql = str_ireplace ( " ` " . $ table . " ` " , " ` " . config ( 'prologue-big.big.project_id' ) . " . " . $ dataset . " . " . $ table . " ` " , $ sql ) ; } if ( ! isset ( $ page ) ) { $ page = 1 ; } if ( $ num > 0 ) { $ sql .= "  limit  " . $ num . "  offset  " . ( $ num * ( $ page - 1 ) ) ; } $ sql = str_ireplace ( " `RAND()` " , " RAND() " , $ sql ) ; return $ sql ; }
Bind data to sql query and replace table name with the correct dataset and project name
 @param object(Illuminate\Database\Eloquent\Builder) $query with ?
Bind data to sql query and replace table name with the correct dataset and project name @param object ( Illuminate \ Database \ Eloquent \ Builder ) $query with ?
//echo $sql;