1. Go to this page and download the library: Download shaozeming/lumen-postgis library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
shaozeming / lumen-postgis example snippets
use Illuminate\Database\Migrations\Migration;
use Shaozeming\LumenPostgis\Schema\Blueprint;
class CreateLocationsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('locations', function(Blueprint $table)
{
$table->increments('id');
$table->string('name');
$table->string('address')->unique();
$table->point('location');
$table->geometry('geom');
$table->polygon('polygon');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('locations');
}
}
use Illuminate\Database\Eloquent\Model;
use Shaozeming\LumenPostgis\Eloquent\PostgisTrait;
use Shaozeming\LumenPostgis\Geometries\Point;
class Location extends Model
{
use PostgisTrait;
protected $fillable = [
'name',
'address'
];
protected $postgisFields = [
'location',
'polygon',
];
}
$location1 = new Location();
$location1->name = 'Googleplex';
$location1->address = '1600 Amphitheatre Pkwy Mountain View, CA 94043';
$location1->location = new Point(37.422009, -122.084047);
$location1->geom = new GeomPoint(37.422009, -122.084047); //这个可以执行成功实现ORM操作gis几何数据。
$location1->save();
$location2 = Location::first();
$location2->location instanceof Point // true
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.