Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Laravel 12 compatibility #35

Merged
merged 6 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
name: run-tests

on: [push, pull_request]
on:
- push
- pull_request

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php: ['8.0', 8.1, 8.2, 8.3]
laravel: [8, 9, 10, 11]
exclude:
- php: '8.0'
laravel: 10
- php: '8.0'
laravel: 11
- php: '8.2'
laravel: 8
- php: '8.1'
laravel: 11

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

services:
mysql:
Expand All @@ -32,9 +18,18 @@ jobs:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

strategy:
fail-fast: true
matrix:
php: [8.2, 8.3, 8.4]
laravel: [11, 12]
stability: [prefer-lowest, prefer-stable]

name: P${{ matrix.php }} - L${{ matrix.laravel }}

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/.idea
/.phpunit.result.cache
/composer.lock
/.phpunit.cache
/.phpunit.cache
.DS_Store
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to `laravel-spatial` will be documented in this file

## 3.0.0 - 2025-02-20
- Laravel 12 and PHP 8.4 support added.
- Laravel 10 and below versions are not supported anymore.
- PHP 8.1 and below versions are not supported anymore.

## 2.0.1 - 2024-11-27
- Fix the incorrect parameter count error while using `ST_SRID` functions with `MariaDB`.

Expand Down
64 changes: 3 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ It supports only MySQL Spatial Data Types and Functions, other RDBMS is on the r

| Version | Supported Laravel Versions |
|---------|----------------------------|
| `2.x` | `^11.0` |
| `1.x` | `^8.0, ^9.0, ^10.0` |
| `3.x` | `^11.0`, `^12.0` |
| `2.x` | `^8.0, ^9.0, ^10.0` |

**Supported data types:**
- `Point`
Expand Down Expand Up @@ -41,43 +41,6 @@ php artisan make:model Address --migration

### 1- Migrations:

## Code Differences Based on Laravel Version

Some code snippets in the project differ before and after Laravel 11 version. Below are the steps to specify these differences:

### For Laravel 8, 9, and 10 Versions

To add a spatial data field, you need to extend the migration from `TarfinLabs\LaravelSpatial\Migrations\SpatialMigration`.

It is a simple abstract class that adds `point` spatial data type to Doctrine mapped types in the constructor.
```php
use TarfinLabs\LaravelSpatial\Migrations\SpatialMigration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends SpatialMigration {

public function up(): void
{
Schema::create('addresses', function (Blueprint $table) {
$table->point('location');
})
}
}
```

The migration above creates an `addresses` table with a `location` spatial column.

> 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.

So you should give an SRID attribute to use spatial indexes in the migrations and indexed columns must be NOT NULL:

```php
Schema::create('addresses', function (Blueprint $table) {
$table->point(column: 'location', srid: 4326);

$table->spatialIndex('location');
})
```
### For Laravel 11 and Above Versions

Expand All @@ -93,7 +56,7 @@ return new class extends Migration {
public function up(): void
{
Schema::create('addresses', function (Blueprint $table) {
$table->geography('location', 'point');
$table->geography('location', subtype: 'point');
})
}

Expand All @@ -106,27 +69,6 @@ When adding a new location column with an index in Laravel, it can be troublesom

To solve this problem, it is recommended to perform a two-step migration like following:

### For Laravel 8, 9, and 10 Versions
```php
public function up()
{
// Add the new location column as nullable
Schema::table('table', function (Blueprint $table) {
$table->point('location')->nullable();
});

// In the second go, set 0,0 values, make the column not null and finally add the spatial index
Schema::table('table', function (Blueprint $table) {
DB::statement("UPDATE `table` SET `location` = POINT(0,0);");

DB::statement("ALTER TABLE `table` CHANGE `location` `location` POINT NOT NULL;");

$table->spatialIndex('location');
});
}
```


### For Laravel 11 and Above Versions

```php
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
}
],
"require": {
"php": "^8.0|^8.1|^8.2|^8.3",
"illuminate/support": "^8.0|^9.0|^10.0|^11.0"
"php": "^8.2|^8.3|^8.4",
"illuminate/support": "^11.0|^12.0"
},
"require-dev": {
"doctrine/dbal": "^3.3",
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0",
"phpunit/phpunit": "^9.0"
"orchestra/testbench": "^9.0|^10.0",
"phpunit/phpunit": "^10.0|^11.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</testsuite>
</testsuites>
<php>
<env name="DB_DRIVER" value="mysql"/>
<env name="DB_CONNECTION" value="mysql"/>
<env name="DB_HOST" value="127.0.0.1"/>
<env name="DB_PORT" value="3306"/>
<env name="DB_USERNAME" value="root"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function up(): void
{
Schema::create('addresses', function (Blueprint $table) {
$table->id();
$table->point('location')->nullable();
$table->geography('location', subtype: 'point')->nullable();
$table->timestamps();
});
}
Expand Down