Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit f343b5d

Browse files
committed
Add instructions to README for enabling PostGIS
1 parent dbc285a commit f343b5d

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

README.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,57 @@ If you are using Laravel < 5.5, you also need to add the DatabaseServiceProvider
5050
```
5151
## Usage
5252

53-
First of all, make sure to enable postgis.
53+
To start, ensure you have PostGIS enabled in your database - you can do this in a Laravel migration or manually via SQL.
54+
55+
### Enable PostGIS via a Laravel migration
56+
57+
Create a new migration file by running
58+
59+
php artisan make:migration enable_postgis
60+
61+
Update the newly created migration file to call the `enablePostgisIfNotExists()` and `disablePostgisIfExists()` methods on the `Schema` facade. For example:
62+
63+
```PHP
64+
<?php
65+
66+
use Illuminate\Database\Migrations\Migration;
67+
use Illuminate\Support\Facades\Schema;
68+
69+
class EnablePostgis extends Migration
70+
{
71+
/**
72+
* Run the migrations.
73+
*
74+
* @return void
75+
*/
76+
public function up()
77+
{
78+
Schema::enablePostgisIfNotExists();
79+
}
80+
81+
/**
82+
* Reverse the migrations.
83+
*
84+
* @return void
85+
*/
86+
public function down()
87+
{
88+
Schema::disablePostgisIfExists();
89+
}
90+
}
91+
```
92+
93+
These methods are safe to use and will only enable / disable the PostGIS extension if relevant - they won't cause an error if PostGIS is / isn't already enabled.
94+
95+
If you prefer, you can use the `enablePostgis()` method which will throw an error if PostGIS is already enabled, and the `disablePostgis()` method twhich will throw an error if PostGIS isn't enabled.
96+
97+
### Enable PostGIS manually
98+
99+
Use an SQL client to connect to your database and run the following command:
54100

55101
CREATE EXTENSION postgis;
56102

57-
To verify that postgis is enabled
103+
To verify that PostGIS is enabled you can run:
58104

59105
SELECT postgis_full_version();
60106

0 commit comments

Comments
 (0)