Skip to content

Commit 97589a7

Browse files
authored
Update WebmanResponseTrait.php
1 parent b60025d commit 97589a7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Traits/WebmanResponseTrait.php

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

29-
public function paginate(\Illuminate\Pagination\LengthAwarePaginator $paginate)
29+
public function paginate(\Illuminate\Pagination\LengthAwarePaginator $paginate, ?callable $callable = null)
3030
{
3131
return $this->success([
3232
'meta' => [
3333
'total' => $paginate->total(),
3434
'current_page' => $paginate->currentPage(),
3535
'per_page' => $paginate->perPage(),
3636
],
37-
'data' => $paginate->items(),
37+
'data' => array_map(function ($item) use ($callable) {
38+
if ($callable) {
39+
return $callable($item) ?? $item;
40+
}
41+
42+
return $item;
43+
}, $paginate->items()),
3844
]);
3945
}
4046

0 commit comments

Comments
 (0)