我想向前端发送一个分页和有序响应。到目前为止,我只能做出有序的回复:
public function getOrders() {
$orders = Order::withTrashed()->orderBy('created_at', 'desc')->get();
$orders = $orders->each(function ($i, $k) {
$i->makeHidden(['stripe_customer_id', 'stripe_token', 'save_cc', 'updated_at', 'deleted_at']);
});
return $this->buildPaginationResponse( $orders, new OrderTransformer(), [] );
}
如果我这样添加paginate(20)
:
我收到此错误:
// Get all orders
public function getOrders() {
$orders = Order::withTrashed()->orderBy('created_at', 'desc')->paginate(20);
$orders = $orders->each(function ($i, $k) {
$i->makeHidden(['stripe_customer_id', 'stripe_token', 'save_cc', 'updated_at', 'deleted_at']);
});
return $this->buildPaginationResponse( $orders, new OrderTransformer(), [] );
}
["方法追加不存在。"]
另外,我无法在代码中的任何位置找到appends
。