如何进行分页和有序响应? Laravel5

时间:2018-06-14 02:39:16

标签: php laravel-5 pagination transformer

我想向前端发送一个分页有序响应。到目前为止,我只能做出有序的回复:

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

0 个答案:

没有答案