You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some code snippets in the project differ before and after Laravel 11 version. Below are the steps to specify these differences:
47
-
48
-
### For Laravel 8, 9, and 10 Versions
49
-
50
-
To add a spatial data field, you need to extend the migration from `TarfinLabs\LaravelSpatial\Migrations\SpatialMigration`.
51
-
52
-
It is a simple abstract class that adds `point` spatial data type to Doctrine mapped types in the constructor.
53
-
```php
54
-
use TarfinLabs\LaravelSpatial\Migrations\SpatialMigration;
55
-
use Illuminate\Database\Schema\Blueprint;
56
-
use Illuminate\Support\Facades\Schema;
57
-
58
-
return new class extends SpatialMigration {
59
-
60
-
public function up(): void
61
-
{
62
-
Schema::create('addresses', function (Blueprint $table) {
63
-
$table->point('location');
64
-
})
65
-
}
66
-
}
67
-
```
68
-
69
-
The migration above creates an `addresses` table with a `location` spatial column.
70
-
71
-
> Spatial columns with no SRID attribute are not SRID-restricted and accept values with any SRID. However, the optimizer cannot use SPATIAL indexes on them until the column definition is modified to include an SRID attribute, which may require that the column contents first be modified so that all values have the same SRID.
72
-
73
-
So you should give an SRID attribute to use spatial indexes in the migrations and indexed columns must be NOT NULL:
74
-
75
-
```php
76
-
Schema::create('addresses', function (Blueprint $table) {
77
-
$table->point(column: 'location', srid: 4326);
78
-
79
-
$table->spatialIndex('location');
80
-
})
81
44
```
82
45
### For Laravel 11 and Above Versions
83
46
@@ -93,7 +56,7 @@ return new class extends Migration {
93
56
public function up(): void
94
57
{
95
58
Schema::create('addresses', function (Blueprint $table) {
96
-
$table->geography('location', 'point');
59
+
$table->geography('location', subtype: 'point');
97
60
})
98
61
}
99
62
@@ -106,27 +69,6 @@ When adding a new location column with an index in Laravel, it can be troublesom
106
69
107
70
To solve this problem, it is recommended to perform a two-step migration like following:
108
71
109
-
### For Laravel 8, 9, and 10 Versions
110
-
```php
111
-
public function up()
112
-
{
113
-
// Add the new location column as nullable
114
-
Schema::table('table', function (Blueprint $table) {
115
-
$table->point('location')->nullable();
116
-
});
117
-
118
-
// In the second go, set 0,0 values, make the column not null and finally add the spatial index
119
-
Schema::table('table', function (Blueprint $table) {
120
-
DB::statement("UPDATE `table` SET `location` = POINT(0,0);");
121
-
122
-
DB::statement("ALTER TABLE `table` CHANGE `location` `location` POINT NOT NULL;");
0 commit comments