@@ -94,6 +94,36 @@ public function render($view = null, $data = [])
94
94
]));
95
95
}
96
96
97
+ /**
98
+ * Get the paginator links as a collection (for JSON responses).
99
+ *
100
+ * @return \Illuminate\Support\Collection
101
+ */
102
+ protected function linkCollection ()
103
+ {
104
+ return collect ($ this ->elements ())->flatMap (function ($ item ) {
105
+ if (! is_array ($ item )) {
106
+ return [['url ' => null , 'label ' => '... ' , 'active ' => false ]];
107
+ }
108
+
109
+ return collect ($ item )->map (function ($ url , $ page ) {
110
+ return [
111
+ 'url ' => $ url ,
112
+ 'label ' => $ page ,
113
+ 'active ' => $ this ->currentPage () === $ page ,
114
+ ];
115
+ });
116
+ })->prepend ([
117
+ 'url ' => $ this ->previousPageUrl (),
118
+ 'label ' => 'Previous ' ,
119
+ 'active ' => false ,
120
+ ])->push ([
121
+ 'url ' => $ this ->nextPageUrl (),
122
+ 'label ' => 'Next ' ,
123
+ 'active ' => false ,
124
+ ]);
125
+ }
126
+
97
127
/**
98
128
* Get the array of elements to pass to the view.
99
129
*
@@ -168,6 +198,7 @@ public function toArray()
168
198
'from ' => $ this ->firstItem (),
169
199
'last_page ' => $ this ->lastPage (),
170
200
'last_page_url ' => $ this ->url ($ this ->lastPage ()),
201
+ 'links ' => $ this ->linkCollection (),
171
202
'next_page_url ' => $ this ->nextPageUrl (),
172
203
'path ' => $ this ->path (),
173
204
'per_page ' => $ this ->perPage (),
0 commit comments