1

Im not using laravel or any framework, i am following the tutorial in O'reilly modern php book. I'm using php version 7;

and when using traits i get this error

Fatal error: Trait 'Geocodable' not found in /Applications/MAMP/htdocs/eli9/RetailStore.php on line 5

here is the following code

Geocodable.php

<?php

trait Geocodable{

    protected $address;

    protected $geocoder;

    protected $geocoderResult;

    public function setGeocoder(\Geocoder\Geocoder $geocoder)
    {
        $this->geocoder = $geocoder;
    }

    public function setAddress($address)
    {
        $this->address = $address;
    }


    public function getLatitude()
    {
        if(!isset($this->geocoderResult)){
            $this->geocodeAddress();
        }

        return $this->geocoderResult->first()->getLatitude();
    }

    public function getLongitude()
    {
        if(!isset($this->geocoderResult)){
            $this->geocodeAddress();
        }

        return $this->geocoderResult->first()->getLongitude();
    }


    public function getcodeAddress()
    {
        $this->geocoderResult = $this->gecoder->geocode($this->address);

        return true;
    }
}

RetailStore.php

<?php

class RetailStore
{
    use Geocodable;
}
BARNOWL
  • 3,326
  • 10
  • 44
  • 80

0 Answers0