Skip to content

Commit 27c9a43

Browse files
committed
axis-order added to query in HasSpatial trait.
1 parent 8be516a commit 27c9a43

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Traits/HasSpatial.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function newQuery(): Builder
6262
$raw = '';
6363

6464
foreach ($this->getLocationCastedAttributes() as $column) {
65-
$raw .= "CONCAT(ST_AsText({$this->getTable()}.{$column}), ',', ST_SRID({$this->getTable()}.{$column})) as {$column}, ";
65+
$raw .= "CONCAT(ST_AsText({$this->getTable()}.{$column}, 'axis-order=long-lat'), ',', ST_SRID({$this->getTable()}.{$column})) as {$column}, ";
6666
}
6767

6868
$raw = substr($raw, 0, -2);

tests/LocationCastTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ public function it_can_set_the_casted_attribute_to_a_point(): void
3939
$this->assertEquals(DB::raw("ST_GeomFromText('POINT({$point->getLng()} {$point->getLat()})')"), $response);
4040
}
4141

42+
/** @test */
43+
public function it_can_set_the_casted_attribute_to_a_point_with_srid(): void
44+
{
45+
// 1. Arrange
46+
$address = new Address();
47+
$point = new Point(27.1234, 39.1234, 4326);
48+
49+
$cast = new LocationCast();
50+
51+
// 2. Act
52+
$response = $cast->set($address, 'location', $point, $address->getAttributes());
53+
54+
// 3. Assert
55+
$this->assertEquals(DB::raw("ST_GeomFromText('POINT({$point->getLng()} {$point->getLat()})', {$point->getSrid()}, 'axis-order=long-lat')"), $response);
56+
}
57+
4258
/** @test */
4359
public function it_can_get_a_casted_attribute(): void
4460
{

0 commit comments

Comments
 (0)