Use laravel-postgis properly

This commit is contained in:
Jonny Barnes 2016-06-27 10:43:47 +01:00
parent 8d39356375
commit 04de40c2de
3 changed files with 14 additions and 14 deletions

View file

@ -41,8 +41,7 @@ class NotesController extends Controller
} }
} }
if ($note->place !== null) { if ($note->place !== null) {
preg_match('/\((.*)\)/', $note->place->location, $matches); $lnglat = explode(' ', $note->place->location);
$lnglat = explode(' ', $matches[1]);
$note->latitude = $lnglat[1]; $note->latitude = $lnglat[1];
$note->longitude = $lnglat[0]; $note->longitude = $lnglat[0];
$note->address = $note->place->name; $note->address = $note->place->name;
@ -110,8 +109,7 @@ class NotesController extends Controller
} }
} }
if ($note->place !== null) { if ($note->place !== null) {
preg_match('/\((.*)\)/', $note->place->location, $matches); $lnglat = explode(' ', $note->place->location);
$lnglat = explode(' ', $matches[1]);
$note->latitude = $lnglat[1]; $note->latitude = $lnglat[1];
$note->longitude = $lnglat[0]; $note->longitude = $lnglat[0];
$note->address = $note->place->name; $note->address = $note->place->name;

View file

@ -32,7 +32,10 @@ class Place extends Model
* *
* @var array * @var array
*/ */
protected $postgisFields = [Point::class, Polygon::class]; protected $postgisFields = [
'location' => Point::class,
'polygon' => Polygon::class,
];
/** /**
* Define the relationship with Notes. * Define the relationship with Notes.
@ -74,18 +77,18 @@ class Place extends Model
return $places; return $places;
} }
/** /*
* Convert location to text. * Convert location to text.
* *
* @param text $value * @param text $value
* @return text * @return text
*/ *
public function getLocationAttribute($value) public function getLocationAttribute($value)
{ {
$result = DB::select(DB::raw("SELECT ST_AsText('$value')")); $result = DB::select(DB::raw("SELECT ST_AsText('$value')"));
return $result[0]->st_astext; return $result[0]->st_astext;
} }*/
/** /**
* Get the latitude from the `location` property. * Get the latitude from the `location` property.
@ -94,9 +97,7 @@ class Place extends Model
*/ */
public function getLatitudeAttribute() public function getLatitudeAttribute()
{ {
preg_match('/\((.*)\)/', $this->location, $latlng); return explode(' ', $this->location)[1];
return explode(' ', $latlng[1])[1];
} }
/** /**
@ -106,9 +107,7 @@ class Place extends Model
*/ */
public function getLongitudeAttribute() public function getLongitudeAttribute()
{ {
preg_match('/\((.*)\)/', $this->location, $latlng); return explode(' ', $this->location)[0];
return explode(' ', $latlng[1])[0];
} }
/** /**

View file

@ -1,5 +1,8 @@
# Changelog # Changelog
## Version {next}
- Better use of `laravel-postgis`
## Version 0.0.5 (2016-06-23) ## Version 0.0.5 (2016-06-23)
- Automatically send webmentions - Automatically send webmentions
- Change `mp-syndicate-to` to `syndicate-to` - Change `mp-syndicate-to` to `syndicate-to`