Use laravel-postgis properly
This commit is contained in:
parent
8d39356375
commit
04de40c2de
3 changed files with 14 additions and 14 deletions
|
@ -41,8 +41,7 @@ class NotesController extends Controller
|
|||
}
|
||||
}
|
||||
if ($note->place !== null) {
|
||||
preg_match('/\((.*)\)/', $note->place->location, $matches);
|
||||
$lnglat = explode(' ', $matches[1]);
|
||||
$lnglat = explode(' ', $note->place->location);
|
||||
$note->latitude = $lnglat[1];
|
||||
$note->longitude = $lnglat[0];
|
||||
$note->address = $note->place->name;
|
||||
|
@ -110,8 +109,7 @@ class NotesController extends Controller
|
|||
}
|
||||
}
|
||||
if ($note->place !== null) {
|
||||
preg_match('/\((.*)\)/', $note->place->location, $matches);
|
||||
$lnglat = explode(' ', $matches[1]);
|
||||
$lnglat = explode(' ', $note->place->location);
|
||||
$note->latitude = $lnglat[1];
|
||||
$note->longitude = $lnglat[0];
|
||||
$note->address = $note->place->name;
|
||||
|
|
|
@ -32,7 +32,10 @@ class Place extends Model
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $postgisFields = [Point::class, Polygon::class];
|
||||
protected $postgisFields = [
|
||||
'location' => Point::class,
|
||||
'polygon' => Polygon::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the relationship with Notes.
|
||||
|
@ -74,18 +77,18 @@ class Place extends Model
|
|||
return $places;
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Convert location to text.
|
||||
*
|
||||
* @param text $value
|
||||
* @return text
|
||||
*/
|
||||
*
|
||||
public function getLocationAttribute($value)
|
||||
{
|
||||
$result = DB::select(DB::raw("SELECT ST_AsText('$value')"));
|
||||
|
||||
return $result[0]->st_astext;
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Get the latitude from the `location` property.
|
||||
|
@ -94,9 +97,7 @@ class Place extends Model
|
|||
*/
|
||||
public function getLatitudeAttribute()
|
||||
{
|
||||
preg_match('/\((.*)\)/', $this->location, $latlng);
|
||||
|
||||
return explode(' ', $latlng[1])[1];
|
||||
return explode(' ', $this->location)[1];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,9 +107,7 @@ class Place extends Model
|
|||
*/
|
||||
public function getLongitudeAttribute()
|
||||
{
|
||||
preg_match('/\((.*)\)/', $this->location, $latlng);
|
||||
|
||||
return explode(' ', $latlng[1])[0];
|
||||
return explode(' ', $this->location)[0];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
# Changelog
|
||||
|
||||
## Version {next}
|
||||
- Better use of `laravel-postgis`
|
||||
|
||||
## Version 0.0.5 (2016-06-23)
|
||||
- Automatically send webmentions
|
||||
- Change `mp-syndicate-to` to `syndicate-to`
|
||||
|
|
Loading…
Add table
Reference in a new issue