Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numeric value out of range: 1416 Cannot get geometry object from data you send to the GEOMETRY field #104

Closed
Edmonbelchev opened this issue Jan 17, 2024 · 5 comments

Comments

@Edmonbelchev
Copy link

 public function setLocationAttribute($value) {
        $this->attributes['location'] = new Point($value['lng'], $value['lat']);
    }

When I try to update my location column trough setAttribute method I get the following error:
Numeric value out of range: 1416 Cannot get geometry object from data you send to the GEOMETRY field

If I update the column with raw sql query everything works fine.

Using Laravel 10.10 & mysql 8.0

@MatanYadaev
Copy link
Owner

Can you please fork and add a failing test?

@reefki
Copy link

reefki commented Jan 27, 2024

I'm facing the same issue, here is my temporary solution that you could try

public function setLocationAttribute($value) {
    $location = new Point($value['lng'], $value['lat']);

    $this->attributes['location'] = DB::raw("ST_GeomFromText('{$location}')");
}

@byt3sage
Copy link

Same issue here!

@MatanYadaev
Copy link
Owner

Guys, I need your help to reproduce this issue. Please add a failing test to the repository, or provide a complete code snippet.

@Edmonbelchev
Copy link
Author

Sorry for the late response. I've managed to make it work but not by using the setAttribute method.
Instead of using the setAttribute method, I identified that it was causing a Numeric value out of range error (1416) and interfering with the GEOMETRY field.

For an alternative approach. Within my model's request class, I created a function called location():

public function location()
{
    // Extract latitude and longitude from the request (adjust accordingly)
    $latitude = $this->input('location.coordinates.0');
    $longitude = $this->input('location.coordinates.1');

    // Create a Point object with spatial coordinates
    return new Point($latitude, $longitude);
}

Then, in the controller's store method, I simply call this function to store the geometric value:
['location' => $request->location()]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants