Skip to content

Commit 89239bd

Browse files
authored
Update WebmanResponseTrait.php
1 parent 1d91545 commit 89239bd

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/Traits/WebmanResponseTrait.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ public static function string2utf8($string = '')
2626
return $string;
2727
}
2828

29+
public function customPaginate($items, $total, $pageSize = 15)
30+
{
31+
$paginate = new \Illuminate\Pagination\LengthAwarePaginator(
32+
items: $items,
33+
total: $total,
34+
perPage: $pageSize,
35+
currentPage: \request('page'),
36+
);
37+
38+
$paginate
39+
->withPath('/'.\request()->path())
40+
->withQueryString();
41+
42+
return $this->paginate($paginate);
43+
}
44+
2945
public function paginate(\Illuminate\Pagination\LengthAwarePaginator $paginate, ?callable $callable = null)
3046
{
3147
return $this->success([
@@ -45,22 +61,6 @@ public function paginate(\Illuminate\Pagination\LengthAwarePaginator $paginate,
4561
]);
4662
}
4763

48-
public function customPaginate($items, $total, $pageSize = 15)
49-
{
50-
$paginate = new \Illuminate\Pagination\LengthAwarePaginator(
51-
items: $items,
52-
total: $total,
53-
perPage: $pageSize,
54-
currentPage: \request('page'),
55-
);
56-
57-
$paginate
58-
->withPath('/'.\request()->path())
59-
->withQueryString();
60-
61-
return $this->paginate($paginate);
62-
}
63-
6464
public function success($data = [], $err_msg = 'success', $err_code = 200, $headers = [])
6565
{
6666
if (is_string($data)) {
@@ -81,6 +81,7 @@ public function success($data = [], $err_msg = 'success', $err_code = 200, $head
8181
$err_code = $config_err_code;
8282
}
8383

84+
$data = $data ?: null;
8485
$res = compact('err_code', 'err_msg', 'data') + array_filter(compact('meta'));
8586

8687
return \response(

0 commit comments

Comments
 (0)