0

我是 Laravel 的新手,我正在迈出第一步。所以我做了这个查询:

public function getPaymentHistory($user_id)
{
    return $this->where('created_by', '=', $user_id)->orderBy('created_at', 'desc')->get();
}

这是结果:

Pyro\Module\Streams\Entry\EntryCollection Object
(
    [model:protected] => Pyro\Module\Payment\Model\PaymentModel Object
        (
            [table:protected] => payment
            [timestamps] => 1
            [columns:protected] => Array
                (
                    [0] => *
                )

            [guarded:protected] => Array
                (
                    [0] => id
                )

            [createdByUserColumns:protected] => Array
                (
                    [0] => id
                    [1] => username
                    [2] => email
                )

            [searchIndexTemplate:protected] => 
            [collectionClass:protected] => Pyro\Module\Streams\Entry\EntryCollection
            [presenterClass:protected] => Pyro\Module\Streams\Entry\EntryPresenter
            [cacheMinutes:protected] => 
            [skip_validation] => 
            [replicated:protected] => 
            [orderByColumn:protected] => id
            [connection:protected] => 
            [primaryKey:protected] => id
            [perPage:protected] => 15
            [incrementing] => 1
            [attributes:protected] => Array
                (
                )

            [original:protected] => Array
                (
                )

            [relations:protected] => Array
                (
                )

            [hidden:protected] => Array
                (
                )

            [visible:protected] => Array
                (
                )

            [appends:protected] => Array
                (
                )

            [fillable:protected] => Array
                (
                )

            [dates:protected] => Array
                (
                )

            [touches:protected] => Array
                (
                )

            [observables:protected] => Array
                (
                )

            [with:protected] => Array
                (
                )

            [morphClass:protected] => 
            [exists] => 
            [softDelete:protected] => 
        )

    [items:protected] => Array
        (
            [0] => Pyro\Module\Payment\Model\PaymentModel Object
                (
                    [table:protected] => payment
                    [timestamps] => 1
                    [columns:protected] => Array
                        (
                            [0] => *
                        )

                    [guarded:protected] => Array
                        (
                            [0] => id
                        )

                    [createdByUserColumns:protected] => Array
                        (
                            [0] => id
                            [1] => username
                            [2] => email
                        )

                    [searchIndexTemplate:protected] => 
                    [collectionClass:protected] => Pyro\Module\Streams\Entry\EntryCollection
                    [presenterClass:protected] => Pyro\Module\Streams\Entry\EntryPresenter
                    [cacheMinutes:protected] => 
                    [skip_validation] => 
                    [replicated:protected] => 
                    [orderByColumn:protected] => id
                    [connection:protected] => 
                    [primaryKey:protected] => id
                    [perPage:protected] => 15
                    [incrementing] => 1
                    [attributes:protected] => Array
                        (
                            [id] => 2
                            [created_at] => 2014-06-17 16:03:15
                            [updated_at] => 
                            [created_by] => 18
                            [ordering_count] => 2
                            [transactionID] => 93P86838PY273320N
                            [orderTime] => 2014-06-20 02:02:38
                            [toReload] => 54.680000305176
                            [amt] => 56
                            [feeAmt] => 1.9199999570847
                            [currencyCode] => USD
                            [paymentStatus] => Completed
                            [pendingReason] => None
                        )

                    [original:protected] => Array
                        (
                            [id] => 2
                            [created_at] => 2014-06-17 16:03:15
                            [updated_at] => 
                            [created_by] => 18
                            [ordering_count] => 2
                            [transactionID] => 93P86838PY273320N
                            [orderTime] => 2014-06-20 02:02:38
                            [toReload] => 54.680000305176
                            [amt] => 56
                            [feeAmt] => 1.9199999570847
                            [currencyCode] => USD
                            [paymentStatus] => Completed
                            [pendingReason] => None
                        )

                    [relations:protected] => Array
                        (
                        )

                    [hidden:protected] => Array
                        (
                        )

                    [visible:protected] => Array
                        (
                        )

                    [appends:protected] => Array
                        (
                        )

                    [fillable:protected] => Array
                        (
                        )

                    [dates:protected] => Array
                        (
                        )

                    [touches:protected] => Array
                        (
                        )

                    [observables:protected] => Array
                        (
                        )

                    [with:protected] => Array
                        (
                        )

                    [morphClass:protected] => 
                    [exists] => 1
                    [softDelete:protected] => 
                )

        )

)

问题,我如何获取或访问以下值:

[attributes:protected] => Array
                        (
                            [id] => 2
                            [created_at] => 2014-06-17 16:03:15
                            [updated_at] => 
                            [created_by] => 18
                            [ordering_count] => 2
                            [transactionID] => 93P86838PY273320N
                            [orderTime] => 2014-06-20 02:02:38
                            [toReload] => 54.680000305176
                            [amt] => 56
                            [feeAmt] => 1.9199999570847
                            [currencyCode] => USD
                            [paymentStatus] => Completed
                            [pendingReason] => None
                        )

这就是我调用模型的方式:

$payment = new PaymentModel();
$payment_history = $payment->getPaymentHistory($user->id);
4

1 回答 1

3

您只需直接访问它们:

$payment = new PaymentModel();
$payment_history = $payment->getPaymentHistory($user->id);
echo $payment_history->amt;  // 56
echo $payment_history->paymentStatus;  // Completed
于 2014-06-22T15:14:02.143 回答