We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 0a30141 + d9b2d9d commit 1aef0b1Copy full SHA for 1aef0b1
1 file changed
src/Mapper.php
@@ -44,15 +44,20 @@ public function getQueryBuilder()
44
* Map a data to a collection of model objects.
45
*
46
* @param array $data An array of data.
47
+ * @param callable $callable The callable you want to call for each row of data.
48
* @return Collection A collection of objects.
49
*/
- protected function mapToObjects($data)
50
+ protected function mapToObjects(array $data, callable $callable = null)
51
{
52
$this->collection->clear();
53
54
if (count($data) > 0) {
55
foreach ($data as $row) {
- $this->collection->add($this->instantiateObject($row));
56
+ if (is_callable($callable)) {
57
+ $this->collection->add(call_user_func($callable, $row));
58
+ } else {
59
+ $this->collection->add($this->instantiateObject($row));
60
+ }
61
}
62
63
0 commit comments