Actually.. I have GeoJson that I send from javascript into controller..My GeoJson My GeoJSON:
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [101.21719328770531, 3.113987284801912]
},
"properties": null
}, {
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[101.18330230120145, 3.046205311794175],
[101.13585492009604, 2.985201536087212],
[101.19008049850223, 2.9174195630794753]
]
},
"properties": null
}]
}
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [101.21719328770531, 3.113987284801912]
},
"properties": null
}, {
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[101.18330230120145, 3.046205311794175],
[101.13585492009604, 2.985201536087212],
[101.19008049850223, 2.9174195630794753]
]
},
"properties": null
}]
}
and then I found this single heterogeneous GEOMETRYCOLLECTIONGEOMETRYCOLLECTION
from this link
So, My sqlSQL something like this:
SELECT public.ST_SetSRID(public.ST_Collect(public.ST_GeomFromGeoJSON(feat->>'geometry')), 4326) as geom
FROM (
SELECT json_array_elements('{
"type":"FeatureCollection",
"features":[{
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[101.21719328770531,3.113987284801912]
},
"properties":null
},{
"type":"Feature",
"geometry":{
"type":"LineString",
"coordinates":[[101.18330230120145,3.046205311794175],
[101.13585492009604,2.985201536087212],
[101.19008049850223,2.9174195630794753]
]
},
"properties":null
}]
}'::json->'features') AS feat) AS f;
SELECT public.ST_SetSRID(public.ST_Collect(public.ST_GeomFromGeoJSON(feat->>'geometry')), 4326) as geom
FROM (
SELECT json_array_elements('{
"type":"FeatureCollection",
"features":[{
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[101.21719328770531,3.113987284801912]
},
"properties":null
},{
"type":"Feature",
"geometry":{
"type":"LineString",
"coordinates":[[101.18330230120145,3.046205311794175],
[101.13585492009604,2.985201536087212],
[101.19008049850223,2.9174195630794753]
]
},
"properties":null
}]
}'::json->'features') AS feat
) AS f;
It can run it ..but. but, how can I insert this into my column geom in my table by using something like this 'geom' => db::raw("from my sql")'geom' => db::raw("from my sql")
?