Search code examples
phplaravellaravel-4eloquentilluminate-container

How to access values from this result


I'm newbie to Laravel and I'm doing my first steps on it. So I made this query:

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

And this is the result:

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] => 
                )

        )

)

Question, how do I get or access to the values below:

[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
                        )

This is how I'm calling the model:

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

Solution

  • You just access them directly:

    $payment = new PaymentModel();
    $payment_history = $payment->getPaymentHistory($user->id);
    echo $payment_history->amt;  // 56
    echo $payment_history->paymentStatus;  // Completed