错误映射:: appends在映射分页中不存在

时间:2019-07-25 12:33:41

标签: laravel-5 pagination

在我的Laravel 5.8应用程序中,我有带有映射的数据库请求,例如:

$paymentItems        = PaymentItem
    ::getByStatus('C', 'payments')
    ->select(
        $this->payment_items_tb . '.*',
        $this->downloads_tb . '.title as payed_item_title',
        $this->users_tb     . '.username as payment_username',
        $this->payments_tb . '.payment_type',
        ...
        $this->payments_tb . '.payer_shipping_address'
    )
    ->orderBy($this->payment_items_tb . '.created_at', 'desc')
    ->join($this->payments_tb, $this->payments_tb . '.id', '=', $this->payment_items_tb . '.payment_id')
    ->join($this->users_tb, $this->users_tb . '.id', '=', $this->payments_tb . '.user_id')
    ->join($this->downloads_tb, $this->downloads_tb . '.id', '=', $this->payment_items_tb . '.item_id')
    ->get()
    ->map(function ($item) {
        return [
            'id'               => $item->id,
            'total'            => $item->price * $item->quantity,
                ....
            'payment_type_label'     => Payment::getPaymentTypeLabel($item->payment_type),
        ];
    });

这对我来说还行,直到我决定将其列表重新分页,例如:

$paymentItems        = PaymentItem
    ::getByStatus('C', 'payments')
    ->select(
        $this->payment_items_tb . '.*',
        $this->downloads_tb . '.title as payed_item_title',
        $this->users_tb     . '.username as payment_username',
        $this->payments_tb . '.payment_type',
        ...
        $this->payments_tb . '.payer_shipping_address'
    )
    ->orderBy($this->payment_items_tb . '.created_at', 'desc')
    ->join($this->payments_tb, $this->payments_tb . '.id', '=', $this->payment_items_tb . '.payment_id')
    ->join($this->users_tb, $this->users_tb . '.id', '=', $this->payments_tb . '.user_id')
    ->join($this->downloads_tb, $this->downloads_tb . '.id', '=', $this->payment_items_tb . '.item_id')
    ->paginate($ref_items_per_pagination, null, null, $page)
    ->onEachSide((int)($ref_items_per_pagination / 2))

    ->map(function ($item) {
        return [
            'id'               => $item->id,
            'total'            => $item->price * $item->quantity,
            ...
            'payment_type_label'     => Payment::getPaymentTypeLabel($item->payment_type),
        ];
    });

但是在我的刀片模板中,我遇到了错误:

Method Illuminate\Support\Collection::appends does not exist. (View: /resources/views/defaultBS41Backend/admin/dashboard/payments_rows.blade.php) {"userId":5,"exception":"[object] (ErrorException(code: 0): Method Illuminate\\Support\\Collection::appends does not exist. (View: /resources/views/defaultBS41Backend/admin/dashboard/payments_rows.blade.php) at /vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php:102, BadMethodCallException(code: 0): Method Illuminate\\Support\\Collection::appends does not exist.

试图显示分页链接块:

    <div class="row">
        {{ $paymentItems->appends([])->links() }}
        <input type="button" class="btn btn-primary" value="Refresh" onclick="javascript:backendDashboard.showPaymentsRows(1); return false;">
    </div>

是否可以解决此错误并显示分页链接?

0 个答案:

没有答案