I was wondering how to use the constructor to initiate the API class I use in the rest of the class. I need it to be self contained to use in separate a controller.
class Coinbase
{
private $configuration;
private $client;
public function __construct($apiKey, $apiSecret)
{
$this->configuration = Configuration::apiKey($apiKey, $apiSecret);
$this->client = Client::create($this->configuration);
}
public static function getBitcoinPrice()
{
$buyPrice = $this->client->getBuyPrice('BTC-EUR');
return var_dump($buyPrice);
}
}
In my controller I call my own Coinbase class like this:
$coinbase = new Coinbase;
return $coinbase->getBitcoinPrice();
This gives the following error:
Using $this when not in object context in Coinbase.php (line 23)
What is a good way to solve this and why is $this->client not configured in the function getBitcoinPrice().
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2sWPVf9
via IFTTT
Aucun commentaire:
Enregistrer un commentaire