0

Im using an API, and I need to display the data in my blade view. Im having trouble doing that. This is what I have in my controller:

public function index() {

    // secret ....
    // key....

    $configuration = Configuration::apiKey($apiKey, $apiSecret);
        $client = Client::create($configuration);

        $BTCSellPrice = $client->getSellPrice('BTC-USD');
        dd($BTCSellPrice);

    return view('welcome', compact(
            'BTCSellPrice'
        ));
}

I get back this:

enter image description here

I tried calling it in the front-end these ways:

{{ $BTCSellPrice }}
{{ $BTCSellPrice->amount }}
{{ $BTCSellPrice['amount'] }}
{{ $BTCSellPrice[0] }}

But keep on getting errors, like:

Cannot use object of type Coinbase\Wallet\Value\Money as array 

Do I need to pass it through a collection or something?

3
  • $BTCSellPrice->amount should work fine. If you're trying to display all the types to check which works, even a single one can cause page errors and prevent others from loading. Commented May 21, 2017 at 19:09
  • Get this error when using your method: ``` Cannot access private property Coinbase\Wallet\Value\Money::$amount ``` Commented May 21, 2017 at 19:34
  • nevermind i found the coinbase php library and looked up the class myself. Updated my answer. Check it. Commented May 21, 2017 at 19:48

3 Answers 3

1

Ok I found the class object being returned and figured out what you need from https://github.com/coinbase/coinbase-php/blob/master/src/Value/Money.php

{{ $BTCSellPrice->getAmount() }}
{{ $BTCSellPrice->getCurrency() }}
Sign up to request clarification or add additional context in comments.

Comments

1

You can not access private fields from other classes. To do this you have to change your private attribute to public ones or write some Getters like this:

class Money {

    private $amount;
    private $currency;

    public function getAmount() {
        return $this->amount;
    }

    public function getCurrency() {
        return $this->currency;
    }
}

Comments

-1

try this

@foreach ($BTCSellPrice as $temp)
   <h3> {{$temp}}</h3>
@endforeach

1 Comment

no that does not work, it displays nothing, tried $temp->amount too

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.