44
55use Binaryk \LaravelRestify \Contracts \RestifySearchable ;
66use Binaryk \LaravelRestify \Repositories \Repository ;
7+ use Binaryk \LaravelRestify \Repositories \RepositoryCollection ;
78use Illuminate \Contracts \Routing \ResponseFactory ;
89use Illuminate \Contracts \Support \Arrayable ;
910use Illuminate \Contracts \Support \Responsable ;
1011use Illuminate \Database \Eloquent \Model ;
1112use Illuminate \Http \JsonResponse ;
13+ use Illuminate \Pagination \AbstractPaginator ;
1214use Illuminate \Support \Arr ;
1315use Illuminate \Support \Facades \App ;
1416use Throwable ;
@@ -200,7 +202,7 @@ public function errors($errors)
200202 */
201203 public function addError ($ message )
202204 {
203- if (! isset ($ this ->errors )) {
205+ if (!isset ($ this ->errors )) {
204206 $ this ->errors = [];
205207 }
206208
@@ -285,7 +287,7 @@ public function __get($key)
285287 return $ this ->$ key ;
286288 }
287289
288- $ code = 'static::REST_RESPONSE_ ' . strtoupper ($ key ). '_CODE ' ;
290+ $ code = 'static::REST_RESPONSE_ ' . strtoupper ($ key ) . '_CODE ' ;
289291
290292 return defined ($ code ) ? constant ($ code ) : null ;
291293 }
@@ -300,7 +302,7 @@ public function __get($key)
300302 */
301303 public function __call ($ func , $ args )
302304 {
303- $ code = 'static::REST_RESPONSE_ ' . strtoupper ($ func ). '_CODE ' ;
305+ $ code = 'static::REST_RESPONSE_ ' . strtoupper ($ func ) . '_CODE ' ;
304306
305307 if (defined ($ code )) {
306308 return $ this ->code (constant ($ code ));
@@ -318,7 +320,7 @@ public function __call($func, $args)
318320 */
319321 public function respond ($ response = null )
320322 {
321- if (! func_num_args ()) {
323+ if (!func_num_args ()) {
322324 $ response = new \stdClass ();
323325 $ response ->data = new \stdClass ();
324326
@@ -654,4 +656,14 @@ public static function created()
654656 {
655657 return (new self ())->code (201 );
656658 }
659+
660+ public static function index (AbstractPaginator $ paginator )
661+ {
662+ return response ()->json ([
663+ 'meta ' => RepositoryCollection::meta ($ paginator ->toArray ()),
664+ 'links ' => RepositoryCollection::paginationLinks ($ paginator ->toArray ()),
665+ 'data ' => $ paginator ->getCollection (),
666+ ]
667+ );
668+ }
657669}
0 commit comments