0
votes

i am trying to create a POSGIS Laravel Backpack CRUD and i generated the model and the controller. i have a model locations with the columns geom , name , address and i am trying to insert manually a value into the DB.

the functional postgis insert should be like this :

insert into locations (geom, name , address) values (st_geomfromtext('POINT(731948.274744 424549.929507)', 3844), 'test' , 'test navicat')

the manually value i am trying to apply to geom field is like this

$this->crud->addField([
        'name'  => 'geom',
        'type'  => 'hidden',
       'value' =>  \DB::raw("st_geomfromtext('POINT(731948.274744 424549.929507)'), 3844)")
    ]);

but the sql error is

SQLSTATE[XX000]: Internal error: 7 ERROR: parse error - invalid geometry HINT: "st" <-- parse error at position 2 within geometry (SQL: insert into "locations" ("name", "address", "geom", "updated_at", "created_at") values (t, t, st_geomfromtext('POINT(731948.274744 424549.929507)'), 3844), 2021-01-21 10:29:15, 2021-01-21 10:29:15) returning "id")

i cannot figure it out how can i solve this problem thank you in advance

1
are you using mysql? if true, what version? - OMR
Hmm it's a bit odd to see you use the value parameter for this. Could you also perhaps use a Laravel Mutator to do this inside the Model itself?laravel.com/docs/8.x/eloquent-mutators#defining-a-mutator - tabacitu
i solved the problem inside the model witha model event upon creation static::creating(function ($questionnaire) { // Same code here }); - brebenel cristian

1 Answers

1
votes

I solved the problem with an event inside the model upon creation of the postgis entry

   static::creating(function ($questionnaire) {
    // Same code here
});