Skip to content

Commit 5019f92

Browse files
committed
Adding Eloquent query capability
1 parent 15a4751 commit 5019f92

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## New version
4+
5+
1. Adding `Eloquent` data source class to handle eloquent query
6+
37
## Version 1.7.0
48

59
1. Detect secure connection to return correct url for assets.

Eloquent.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace koolreport\laravel;
4+
5+
use \koolreport\core\Utility;
6+
7+
class Eloquent extends \koolreport\core\DataSource
8+
{
9+
protected $builder;
10+
/**
11+
* Insert eloquent buikder to the pipe.
12+
*
13+
* @param mixed $builder
14+
*/
15+
public function query($builder)
16+
{
17+
$this->builder = $builder;
18+
return $this;
19+
}
20+
21+
/**
22+
* Start piping data
23+
*
24+
* @return null
25+
*/
26+
public function start()
27+
{
28+
$metaData = null;
29+
foreach($this->builder->cursor() as $item)
30+
{
31+
if(!$metaData)
32+
{
33+
$metaData = array(
34+
"columns"=>array()
35+
);
36+
foreach($item->toArray() as $k=>$v)
37+
{
38+
$metaData["columns"][$k] = array(
39+
"type"=>Utility::guessType($v)
40+
);
41+
}
42+
$this->sendMeta($metaData, $this);
43+
$this->startInput(null);
44+
}
45+
$this->next($item->toArray(), $this);
46+
}
47+
$this->endInput(null);
48+
}
49+
}

0 commit comments

Comments
 (0)