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
+
37
50
To add a spatial data field, you need to extend the migration from `TarfinLabs\LaravelSpatial\Migrations\SpatialMigration`.
38
51
39
52
It is a simple abstract class that adds `point` spatial data type to Doctrine mapped types in the constructor.
40
-
41
53
```php
42
54
use TarfinLabs\LaravelSpatial\Migrations\SpatialMigration;
43
55
use Illuminate\Database\Schema\Blueprint;
44
56
use Illuminate\Support\Facades\Schema;
45
57
46
58
return new class extends SpatialMigration {
47
-
59
+
48
60
public function up(): void
49
61
{
50
62
Schema::create('addresses', function (Blueprint $table) {
51
63
$table->point('location');
52
64
})
53
65
}
54
-
55
66
}
56
67
```
57
68
@@ -64,16 +75,38 @@ So you should give an SRID attribute to use spatial indexes in the migrations an
64
75
```php
65
76
Schema::create('addresses', function (Blueprint $table) {
66
77
$table->point(column: 'location', srid: 4326);
67
-
78
+
68
79
$table->spatialIndex('location');
69
80
})
70
81
```
82
+
### For Laravel 11 and Above Versions
83
+
84
+
From Laravel 11 onwards, migrations are created as follows:
85
+
86
+
```php
87
+
use Illuminate\Database\Migrations\Migration;
88
+
use Illuminate\Database\Schema\Blueprint;
89
+
use Illuminate\Support\Facades\Schema;
90
+
91
+
return new class extends Migration {
92
+
93
+
public function up(): void
94
+
{
95
+
Schema::create('addresses', function (Blueprint $table) {
96
+
$table->geography('location', 'point');
97
+
})
98
+
}
99
+
100
+
}
101
+
```
102
+
In Laravel 11, the methods **point**, **lineString**, **polygon**, **geometryCollection**, **multiPoint**, **multiLineString**, and **multiPolygon** have been removed. Therefore, we are updating to use the **geography** method instead. The `geography` method sets the default SRID value to 4326.
71
103
72
104
#### Issue with adding a new location column with index to an existing table:
73
105
When adding a new location column with an index in Laravel, it can be troublesome if you have existing data. One common mistake is trying to set a default value for the new column using `->default(new Point(0, 0, 4326))`. However, `POINT` columns cannot have a default value, which can cause issues when trying to add an index to the column, as indexed columns cannot be nullable.
74
106
75
107
To solve this problem, it is recommended to perform a two-step migration like following:
76
108
109
+
### For Laravel 8, 9, and 10 Versions
77
110
```php
78
111
public function up()
79
112
{
@@ -93,6 +126,28 @@ public function up()
93
126
}
94
127
```
95
128
129
+
130
+
### For Laravel 11 and Above Versions
131
+
132
+
```php
133
+
public function up()
134
+
{
135
+
// Add the new location column as nullable
136
+
Schema::table('table', function (Blueprint $table) {
0 commit comments