- How do I install grimzy/laravel-mysql-spatial in a Laravel app?
- Install it with Composer using composer require grimzy/laravel-mysql-spatial, then register the package service provider if your Laravel version does not auto-discover it. Publish any provided configuration if needed and run your migrations. The package hooks into Laravel's schema Blueprint and Eloquent casts, so no separate daemon or connection change is required.
- Which Laravel and PHP versions does grimzy/laravel-mysql-spatial support?
- The last release was October 2020, so the supported matrix is roughly Laravel 6, 7, and 8 on PHP 7.x. On Laravel 9, 10, or 11 with PHP 8.1+ expect friction with illuminate/* constraints, doctrine/dbal schema introspection, and PHP 8 return-type strictness. Widening the Composer constraints and patching the grammar or cast classes is usually small but becomes your team's maintenance work.
- How do I add Point, Polygon, or geometry columns in a Laravel migration?
- Use the spatial column methods the package adds to Laravel's schema Blueprint, such as point(), polygon(), linestring(), and geometrycollection(), inside your migration. These map to MySQL spatial data types rather than generic strings. Remember that MySQL spatial indexes require NOT NULL columns, so plan nullability deliberately.
- How do I cast a MySQL geometry column to a Point or Polygon in Eloquent?
- Add the package's spatial cast to the $casts array on your Eloquent model, for example 'location' => Point::class or 'area' => Polygon::class. The cast hydrates the raw WKT/WKB value into a typed value object instead of leaving a string in your model. That keeps spatial logic out of controllers and makes geometry values easier to test.
- How do I query rows by distance with grimzy/laravel-mysql-spatial?
- Use the query builder methods the package adds, such as whereDistance() and orderByDistance(), passing a Point and a distance constraint. These methods wrap MySQL spatial functions like ST_Distance_Sphere so you avoid raw DB::raw() expressions. Verify results against your MySQL version and SRID convention because distance semantics differ between MySQL 5.7 and 8.0.
- How do I use whereWithin, whereContains, or intersects with this package?
- The package adds spatial predicate methods such as whereWithin(), whereContains(), and whereIntersects() to the Laravel query builder. Pass the geometry value object, such as a Polygon, and the package builds the corresponding MySQL ST_Within, ST_Contains, or ST_Intersects expression. These predicates are useful for bounding-box filtering and containment checks but should be tested against your actual MySQL or MariaDB flavor.
- Does grimzy/laravel-mysql-spatial work with MySQL 8 and SRID 4326?
- It targets MySQL spatial types, but MySQL 8 changed SRID and axis-order semantics. Geometries tagged SRID 4326 are interpreted latitude-first, which can invert longitude-first assumptions and silently mirror data. Treat geodesy correctness as a named ownership item and add tests that assert coordinate order, not just schema validity.
- Do I need a SPATIAL INDEX for spatial queries in Laravel MySQL?
- Yes for production-scale read-heavy filtering, but SPATIAL INDEX has constraints: the column must be NOT NULL and your InnoDB version must support it. Naive adoption can leave you with table scans that only show up under real data volume. Validate index usage with EXPLAIN rather than assuming the package's query methods will use the index.
- Is grimzy/laravel-mysql-spatial still maintained?
- No release has shipped since October 2020, and it is effectively a single-maintainer package with little evidence of broad production battle-testing. Treat adoption as an adopt-and-own decision: budget for fork maintenance, Composer constraint updates, and PHP 8 compatibility patches. Decide in advance who owns that patch and what lead time is acceptable.
- What are alternatives to grimzy/laravel-mysql-spatial for geospatial Laravel apps?
- If MySQL is your system of record, this package is a thin, expressive option for geometry columns and spatial predicates. If you need PostGIS, complex topology predicates, or multi-store portability, a dedicated spatial database or a more actively maintained library is a better fit. Also confirm the license before commercial use because repository metadata reports NOASSERTION rather than a detected MIT license.