Skip to content

Numeric value out of range when inserting  #80

Closed
@pelmered

Description

@pelmered

I get this error message when I do a simple insert to a Point field:

SQLSTATE[22003]: Numeric value out of range: 1416 Cannot get geometry object from data you send to the GEOMETRY field (SQL: insert into `addresses` (`type`, `address_line_1`, `address_line_2`, `city`, `postal_code`, `country`, `user_uuid`, `uuid`, `location`, `updated_at`, `created_at`) values (billing, Drottninggatan 11, , Stockholm, 111 51, SE, ad120958-31b9-44da-92a8-e990c20eac42, 5bfa2e46-8fa5-4fbc-b818-0066adc858b8, 59.3315493 18.0637367, 2019-03-07 17:07:33, 2019-03-07 17:07:33))

The only solutions I can find is to add SpatialTrait and $spatialFields, but I already have them. This the relevant parts of the model:

<?php 

class Address extends Model
{
    use SpatialTrait;

    protected $spatialFields = ['location'];

    public static function boot()
    {
        parent::boot();

        self::creating(function (Address $address) {

            if (
                empty($address->attributes['location']) &&
                $address->isComplete()
            ) {
                $geocoded = app('geocoder')->geocodeAddress($address);
                $address->attributes['location'] = new Point($geocoded['latitude'], $geocoded['longitude']);
            }
        });
    }

    public function isComplete()
    {
        return isset($this->type, $this->address_line_1, $this->city, $this->postal_code, $this->country);
    }
}

I have double and triple checked the code, but I can't find anything wrong.
Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions