Skip to content

Commit faabe89

Browse files
committed
Add retrieving method for in query method, support call
1 parent b6918a3 commit faabe89

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
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+
## Version 2.1.0
4+
5+
1. Add retrieving method for `Eloquent` in query method, support `lazy` call.
6+
37
## Version 2.0.0
48

59
1. Adding `Eloquent` data source class to handle eloquent query

Eloquent.php

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,23 @@
66

77
class Eloquent extends \koolreport\core\DataSource
88
{
9-
protected $builder;
109
/**
1110
* Insert eloquent buikder to the pipe.
1211
*
1312
* @param mixed $builder
1413
*/
15-
public function query($builder)
14+
protected $builder;
15+
protected $retrievingMethod;
16+
17+
public function query($builder, $retrievingMethod = null)
1618
{
1719
$this->builder = $builder;
20+
$this->retrievingMethod = $retrievingMethod;
1821
return $this;
1922
}
2023

21-
/**
22-
* Start piping data
23-
*
24-
* @return null
25-
*/
26-
public function start()
24+
public function sendMetaAndItem($metaData, $item)
2725
{
28-
$metaData = null;
29-
foreach($this->builder->cursor() as $item)
30-
{
3126
if(!$metaData)
3227
{
3328
$metaData = array(
@@ -43,6 +38,26 @@ public function start()
4338
$this->startInput(null);
4439
}
4540
$this->next($item->toArray(), $this);
41+
}
42+
43+
/**
44+
* Start piping data
45+
*
46+
* @return null
47+
*/
48+
public function start()
49+
{
50+
$metaData = null;
51+
if ($this->retrievingMethod == 'lazy') {
52+
foreach($this->builder::lazy() as $item)
53+
{
54+
$this->sendMetaAndItem($metaData, $item);
55+
}
56+
} else {
57+
foreach($this->builder->cursor() as $item)
58+
{
59+
$this->sendMetaAndItem($metaData, $item);
60+
}
4661
}
4762
$this->endInput(null);
4863
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "koolreport/laravel",
3-
"version":"2.0.0",
3+
"version":"2.1.0",
44
"description": "Allow to use KoolReport seamlessly in Laravel",
55
"keywords": ["PHP","Reporting Tools","Data Report","laravel","KooLReport Laravel","Laravel Report","laravel reporting","laravel reporting tool"],
66
"homepage": "https://www.koolreport.com",

0 commit comments

Comments
 (0)