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

fix sr_id for geometry while updating record #85

Closed
wants to merge 2 commits into from

Conversation

mitulgolakiya
Copy link

Thanks for this awesome package. It is completely working fine when we create a record. But I got one minor error when we try to update a record. Actually, it's not getting proper sr_id in a query.

Here is the migration that I have created:

Schema::create('locations', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->point('location', 'GEOMETRY', 27700);
    $table->timestamps();
});

This is my Model:

class Location extends Model
{
    use PostgisTrait;

    protected $fillable = [
        'name'
    ];

    protected $postgisFields = [
        'location'
    ];

    protected $postgisTypes = [
        'location' => [
            'geomtype' => 'geometry',
            'srid' => 27700
        ]
    ];
}

And this is how I'm creating and updating record.

$location = new \App\Location();
$location->name = "Location1";
$location->location = new Point(37.422009, -122.084047);;
$location->save();

$createdLocation = \App\Location::find($location->id);
$createdLocation->location = new Point(37.422009, -123.084047);
$createdLocation->save();

dd($createdLocation->toArray());

so while save function, I am getting following error:

SQLSTATE[42804]: Datatype mismatch: 7 ERROR:  column "location" is of type geometry but expression is of type geography
LINE 1: update "locations" set "location" = public.ST_GeogFromText('...
                                            ^
HINT:  You will need to rewrite or cast the expression. (SQL: update "locations" set "location" = public.ST_GeogFromText('POINT(-123.084047 37.422009)'), "updated_at" = 2017-09-16 14:03:47 where "id" = 1)

@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 84.444% when pulling 8696d9d on InfyOmLabs:master into 278a6c1 on njbarrett:master.

@njbarrett
Copy link
Collaborator

Hey @mitulgolakiya thanks for the PR.
It looks like the code needs to handle a null value - have a look at the travis build log.
Thanks!

@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 84.543% when pulling e465a40 on InfyOmLabs:master into b751206 on njbarrett:master.

@mstaack mstaack closed this Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants