7

I have a table with a column of type Spatial point ,,

I want the query to insert the values of that column with laravel

and if there a queries to get items within a specific range ?

any help here ??

That's my table here :

public function up()
{
    Schema::create('markers', function(Blueprint $table)
    {
        $table->integer('marker_id')->primary();
        $table->string('marker_name', 45);
        $table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
    });
    DB::raw("ALTER TABLE markers ADD COLUMN location POINT");
}
2
  • insert single value?post your table and code Commented Feb 21, 2015 at 11:54
  • I edited my question with the table ,, Commented Feb 21, 2015 at 12:03

1 Answer 1

11

You can insert data as follows:

ModelName::firstOrCreate(
    array(
        ..//other fields
        'location' => DB::raw("(GeomFromText('POINT(37.774929 -122.419415)'))")
    )
);

To retrieve data:

SELECT X(`location`), Y(`location`) FROM markers;

I too was stuck here & got help from: Spatial Point functions using Laravel Eloquent ORM. Hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

As a side note. I got the error GeomFromText does not exist. So I had to change it to ST_GeomFromText

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.