jeudi 25 avril 2019

Call to undefined method Grimzy\LaravelMysqlSpatial\Eloquent\SpatialExpression::getLat()

I'm using laravel-mysql-spatial package to store geo-cordinates in database. while using it in other places like, everything works fine. but when I use it in an observer, the error came

Call to undefined method Grimzy\LaravelMysqlSpatial\Eloquent\SpatialExpression::getLat()

The following code is not giving point object.

public function created(Beneficiary $beneficiary)
    {
        dd($beneficiary);
    }

but when I retrive the data using the created id like below, it worked fine then

public function created(Beneficiary $beneficiary)
    {
        $beneficiary = Beneficiary::find($beneficiary->id);
        dd($beneficiary);
    }

but the above is not considered as a good practice. I'm already having an object and making an another call for it.

Expected Result. This result came after I make a call to retrieve the same data

#attributes: array:19 [▼
    "id" => 95
    "name" => "Test beneficiary"
    "phone" => "80572*****"
    "coordinates" => Point {#547 ▼
      #lat: 30.3165
      #lng: 78.0322
    }

This is how I'm getting the result.

#attributes: array:16 [▼
    "name" => "Test beneficiary"
    "phone" => "80572*****"
    "coordinates" => SpatialExpression {#521 ▼
      #value: Point {#510 ▼
        #lat: 30.3165
        #lng: 78.0322
      }
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire