Laravel给出错误未定义的属性:stdClass :: $ latitude

时间:2019-02-19 13:51:49

标签: php laravel laravel-5 laravel-4 laravel-5.6

我正在尝试使用软件包a link!安装后,当我尝试运行该项目时,它只是失败了,并开始显示“未定义属性”错误。 因此,如果有人可以帮助我。 这些错误很难完成我的项目

IPstack.php     

namespace Voerro\Laravel\VisitorTracker\Geoip;

class Ipstack extends Driver
{
    protected function getEndpoint($ip)
    {
        $key = config('visitortracker.ipstack_key');

        return "http://api.ipstack.com/{$ip}?access_key={$key}";
    }

    public function latitude()
    {
        return $this->data->latitude;
    }

    public function longitude()
    {
        return $this->data->longitude;
    }

    public function country()
    {
        return $this->data->country_name;
    }

    public function countryCode()
    {
        return $this->data->country_code;
    }

    public function city()
    {
        return $this->data->city;
    }
}

Driver.php         

namespace Voerro\Laravel\VisitorTracker\Geoip;

use Voerro\Laravel\VisitorTracker\Models\Visit;
use GuzzleHttp\Client;

abstract class Driver
{
    /**
     * Holds data fetched from a remote geoapi service
     *
     * @var Object
     */
    protected $data;

    /**
     * Fetch data from a remote geoapi service
     *
     * @param Voerro\Laravel\VisitorTracker\Models\Visit $visit
     * @return $this
     */
    public function getDataFor(Visit $visit)
    {
        $client = new Client();

        $response = $client->get($this->getEndpoint($visit->ip));

        if ($response->getStatusCode() == 200) {
            $this->data = json_decode($response->getBody()->getContents());

            return $this;
        }

        return null;
    }

    /**
     * Returns an endpoint to fetch the data from
     *
     * @param string $ip IP address to fetch geolocation data for
     * @return string
     */
    abstract protected function getEndpoint($ip);

    /**
     * Returns latitude from the fetched data
     *
     * @return string
     */
    abstract public function latitude();

    /**
     * Returns longitude from the fetched data
     *
     * @return string
     */
    abstract public function longitude();

    /**
     * Returns country from the fetched data
     *
     * @return string
     */
    abstract public function country();

    /**
     * Returns country code from the fetched data
     *
     * @return string
     */
    abstract public function countryCode();

    /**
     * Returns city from the fetched data
     *
     * @return string
     */
    abstract public function city();
}

因此,如果可以找到错误,则是driver.php。

0 个答案:

没有答案