@@ -38,6 +38,8 @@ class QueryBuilder
38
38
39
39
protected $ excludedParameters = [];
40
40
41
+ protected $ appends = [];
42
+
41
43
protected $ query ;
42
44
43
45
protected $ result ;
@@ -88,7 +90,13 @@ public function build()
88
90
89
91
public function get ()
90
92
{
91
- return $ this ->query ->get ();
93
+ $ result = $ this ->query ->get ();
94
+
95
+ if ($ this ->hasAppends ()) {
96
+ $ result = $ this ->addAppendsToModel ($ result );
97
+ }
98
+
99
+ return $ result ;
92
100
}
93
101
94
102
public function paginate ()
@@ -97,7 +105,13 @@ public function paginate()
97
105
throw new Exception ("You can't use unlimited option for pagination " , 1 );
98
106
}
99
107
100
- return $ this ->basePaginate ($ this ->limit );
108
+ $ result = $ this ->basePaginate ($ this ->limit );
109
+
110
+ if ($ this ->hasAppends ()) {
111
+ $ result = $ this ->addAppendsToModel ($ result );
112
+ }
113
+
114
+ return $ result ;
101
115
}
102
116
103
117
public function lists ($ value , $ key )
@@ -234,6 +248,11 @@ private function setWheres($parameters)
234
248
$ this ->wheres = $ parameters ;
235
249
}
236
250
251
+ private function setAppends ($ appends )
252
+ {
253
+ $ this ->appends = explode (', ' , $ appends );
254
+ }
255
+
237
256
private function addWhereToQuery ($ where )
238
257
{
239
258
extract ($ where );
@@ -310,6 +329,11 @@ private function hasIncludes()
310
329
return (count ($ this ->includes ) > 0 );
311
330
}
312
331
332
+ private function hasAppends ()
333
+ {
334
+ return (count ($ this ->appends ) > 0 );
335
+ }
336
+
313
337
private function hasGroupBy ()
314
338
{
315
339
return (count ($ this ->groupBy ) > 0 );
@@ -352,6 +376,16 @@ private function customFilterName($key)
352
376
return 'filterBy ' . studly_case ($ key );
353
377
}
354
378
379
+ private function addAppendsToModel ($ result )
380
+ {
381
+ $ result ->map (function ($ item ) {
382
+ $ item ->append ($ this ->appends );
383
+ return $ item ;
384
+ });
385
+
386
+ return $ result ;
387
+ }
388
+
355
389
/**
356
390
* Paginate the given query.
357
391
*
0 commit comments