@@ -166,6 +166,13 @@ abstract class BaseEngine implements DataTableEngineContract
166
166
*/
167
167
protected $ serializer ;
168
168
169
+ /**
170
+ * Array of data to append on json response.
171
+ *
172
+ * @var array
173
+ */
174
+ private $ appends ;
175
+
169
176
/**
170
177
* Setup search keyword.
171
178
*
@@ -675,11 +682,11 @@ abstract public function paging();
675
682
*/
676
683
public function render ($ object = false )
677
684
{
678
- $ output = [
679
- 'draw ' => (int ) $ this ->request ['draw ' ],
680
- 'recordsTotal ' => $ this ->totalRecords ,
681
- 'recordsFiltered ' => $ this ->filteredRecords ,
682
- ];
685
+ $ output = $ this -> appends + [
686
+ 'draw ' => (int ) $ this ->request ['draw ' ],
687
+ 'recordsTotal ' => $ this ->totalRecords ,
688
+ 'recordsFiltered ' => $ this ->filteredRecords ,
689
+ ];
683
690
684
691
if (isset ($ this ->transformer )) {
685
692
$ fractal = new Manager ();
@@ -800,4 +807,24 @@ public function isCaseInsensitive()
800
807
{
801
808
return Config::get ('datatables.search.case_insensitive ' , false );
802
809
}
810
+
811
+ /**
812
+ * Append data on json response.
813
+ *
814
+ * @param mixed $key
815
+ * @param mixed $value
816
+ * @return $this
817
+ */
818
+ public function with ($ key , $ value = '' )
819
+ {
820
+ if (is_array ($ key )) {
821
+ $ this ->appends = $ key ;
822
+ } elseif (is_callable ($ value )) {
823
+ $ this ->appends [$ key ] = value ($ value );
824
+ } else {
825
+ $ this ->appends [$ key ] = value ($ value );
826
+ }
827
+
828
+ return $ this ;
829
+ }
803
830
}
0 commit comments