How grimzy/laravel-mysql-spatial works
This package extends Laravel’s database and Eloquent layers so applications can define MySQL spatial columns, persist typed geometries, retrieve them as objects, and query by spatial relationships or distance. The main path runs from Laravel application code through the registered MySQL connection and spatial schema/query extensions to MySQL. Geometry value types provide WKT/WKB and GeoJSON representations. README capabilities include SRID-aware fields and geometries, spatial indexes, and distance ordering. The graph follows documented behavior and sampled source; unsampled subsystem wiring is left out.
Main entry points: Geometry.php Geometry types · SpatialTrait.php Spatial trait · MysqlConnection.php MySQL connection · SpatialServiceProvider.php Service provider
Components 18
Laravel integration
- Service provider
src/SpatialServiceProvider.php - Connection factory
src/Connectors/ConnectionFactory.php - MySQL connection
src/MysqlConnection.php
Spatial schema
- Schema builder
src/Schema/Builder.php - Spatial blueprint
src/Schema/Blueprint.php - MySQL grammar
src/Schema/Grammars/MySqlGrammar.php
Eloquent spatial data
- Spatial trait
src/Eloquent/SpatialTrait.php - Spatial query builder
src/Eloquent/Builder.php - Base query builder
src/Eloquent/BaseBuilder.php - Spatial expression
src/Eloquent/SpatialExpression.php
Geometry values
- Geometry types
src/Types/Geometry.php - Type factory
src/Types/Factory.php - Geometry collections
src/Types/GeometryCollection.php
Other components
- Laravel application
- MySQL
- Doctrine DBAL
- Eloquent model
- GeoJSON library
Connections 26
- Laravel application → Service provider: registers
- Service provider → Connection factory: binds
- Connection factory → MySQL connection: creates
- MySQL connection → Schema builder: provides
- MySQL connection → MySQL: connects
- MySQL connection → Doctrine DBAL: registers mappings
- Service provider → Doctrine DBAL: registers types
- Laravel application → Schema builder: defines schema
- Schema builder → Spatial blueprint: creates
- Spatial blueprint → MySQL grammar: compiles spatial SQL
- MySQL grammar → MySQL: emits SQL
- Laravel application → Eloquent model: uses
- Eloquent model → Spatial trait: uses
- Spatial trait → Spatial query builder: creates
- Spatial trait → Base query builder: creates
- Spatial trait → Spatial expression: wraps geometry
- Base query builder → Spatial expression: binds value
- Spatial trait → Geometry types: parses WKB
- Spatial trait → MySQL: queries spatial functions
- Laravel application → Geometry types: creates geometry
- Type factory → Geometry types: constructs types
- Geometry collections → Geometry types: contains geometries
- Geometry collections → GeoJSON library: converts GeoJSON
- Geometry types → GeoJSON library: converts GeoJSON
- Geometry types → MySQL: encodes spatial values
- MySQL → Geometry types: returns spatial values