1

I develop an application which allows to post(show) a list of restaurants according to the location(localization) of the user.

For that purpose, I have a base(basis) of datum containing bars with their latitudes-longitudes.

My database is under postgresql and I would like to use, all my back-service(back-office) is under Laravel. At present to add a POINT, I make: ST_GeogFromText('SRID=4326;(110 30)'), but on Laravel, the request SQL ( db:seed ) includes the ST_ guillement enter.

DB::table('establishments')->insert(['location' =>ST_GeogFromText(\'SRID=4326;POINT(-110 30)\'),]), but ST_GeogFromText is not a fonction -- The error message:

parse error - invalid geometry HINT: "ST"

How may I make to manage PostgreSQL-Postgis and Laravel?

5
  • Have you tried ST_GeogFromText('SRID=4326;POINT(110 30)');? Commented May 18, 2018 at 13:40
  • I didn't quite get the issue here. Are you unable to add points to your db? If so, can you elaborate a bit more on the procedure and the error message? Commented May 18, 2018 at 13:42
  • I try to add an entity in my db with Laravel seeding, so i make DB::table('establishments')->insert(['location' => ST_GeogFromText(\'SRID=4326;POINT(-110 30)\'),]), but ST_GeogFromText is not a fonction -- The error message are : parse error - invalid geometry HINT: "ST" Commented May 18, 2018 at 13:52
  • Just to make it clearer: you're sure that the PostGIS extension is installed in your database, right? Commented May 18, 2018 at 13:58
  • Yes, i'm sure, but i think it is laravel the problem Commented May 18, 2018 at 14:16

1 Answer 1

1

ST_GeogFromText is a PostGIS function not a PHP/Laravel function, and you cannot wrap it in quotes (i.e. ""), as Laravel will then consider it a string.

Instead, pass a raw query expression like below:

DB::table('establishments')->insert([
    'location' => DB::raw("ST_GeogFromText('SRID=4326;POINT(-110 30)')"),
    // your other columns & values
]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.