Skip to content

Commit 700fdb4

Browse files
committed
Split the Eloquent Builder into a Trait so that it can be merged with other packages Builders (grimzy#17).
1 parent 84e80bf commit 700fdb4

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

src/Eloquent/Builder.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,9 @@
22

33
namespace Grimzy\LaravelMysqlSpatial\Eloquent;
44

5-
use Grimzy\LaravelMysqlSpatial\Types\GeometryInterface;
65
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
76

87
class Builder extends EloquentBuilder
98
{
10-
public function update(array $values)
11-
{
12-
foreach ($values as $key => &$value) {
13-
if ($value instanceof GeometryInterface) {
14-
$value = $this->asWKT($value);
15-
}
16-
}
17-
18-
return parent::update($values);
19-
}
20-
21-
protected function asWKT(GeometryInterface $geometry)
22-
{
23-
return $this->getQuery()->raw("ST_GeomFromText('".$geometry->toWKT()."')");
24-
}
9+
use SpatialBuilderTrait;
2510
}

src/Eloquent/SpatialBuilderTrait.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Grimzy\LaravelMysqlSpatial\Eloquent;
4+
5+
use Grimzy\LaravelMysqlSpatial\Types\GeometryInterface;
6+
7+
trait SpatialBuilderTrait
8+
{
9+
public function update(array $values)
10+
{
11+
foreach ($values as $key => &$value) {
12+
if ($value instanceof GeometryInterface) {
13+
$value = $this->asWKT($value);
14+
}
15+
}
16+
17+
return parent::update($values);
18+
}
19+
20+
protected function asWKT(GeometryInterface $geometry)
21+
{
22+
return $this->getQuery()->raw("ST_GeomFromText('".$geometry->toWKT()."')");
23+
}
24+
}

0 commit comments

Comments
 (0)