Ошибка выдачи Laravel Неопределенное свойство: stdClass :: $ latitude - PullRequest
0 голосов
/ 19 февраля 2019

Я пытаюсь использовать пакет ссылку !и когда после установки я попытался запустить этот проект, он просто потерпел неудачу и начал выдавать ошибку Undefined Property.Так что если кто-нибудь может мне помочь.Все труднее завершить мой проект с этими ошибками

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, если вы можете найти ошибку.

...