freepeace13/laraversine
A lightweight Laravel package for Haversine distance calculations. Compute great-circle distances between latitude and longitude points, then use them for nearby searches, radius filtering, or distance sorting in PHP applications.
Architecture fit: Laraversine is a composer-installable Laravel package that layers haversine distance querying onto Eloquent. The v1.1.0 additions — a Distance value object exposed through a distance() accessor, plus a clearer exception when nearestFirst() is invoked without a preceding nearby() — indicate a trait/query-scope-based architecture rather than a standalone service. That is a natural fit for Laravel codebases that already model coordinates as columns on Eloquent models, and it avoids introducing a separate geospatial service or extension (e.g. PostGIS) for straightforward radius queries.
Integration feasibility: High. This is a minor release with additive features and a bug fix; no breaking changes are signalled by the semver bump or the changelog. Adoption requires only a composer update and, optionally, refactoring distance consumers to use the new value object. The bug fix is strictly defensive — converting a confusing downstream failure into an explicit error — so it carries essentially no integration cost.
Technical risk: Low, with caveats. The primary risk is not this release but the package's maturity: it is at v1.x with a small issue/PR history, so API stability and long-term maintenance should be validated. Second, the nearestFirst()-before-nearby() fix implies the query API is stateful — ordering depends on a prior scope invocation on the same builder instance. The new exception makes the failure mode legible but does not remove the statefulness, which is worth understanding before chaining these scopes into larger query pipelines. Third, introducing a Distance value object raises questions about how it serialises into JSON responses and whether existing consumers expected a raw numeric from distance().
Key questions:
distance() previously return a scalar? If so, the value object is a behavioural change for existing consumers despite the minor version bump.Distance castable/serialisable (JSON, array) and does it expose unit conversion, or is it a thin wrapper over a float?WHERE clauses efficiently.Stack fit: Suitable for any Laravel application on a currently supported PHP version that needs proximity search without standing up specialised geospatial infrastructure. It is a poor fit for high-volume geo workloads where a spatial index (PostGIS, MySQL SPATIAL, or a dedicated search service) is warranted.
Migration path: From v1.0.0 this is a drop-in upgrade — no code changes are required to remain functional. The recommended path is: upgrade in a development branch, run the existing test suite, then opportunistically adopt the Distance value object in new code rather than retrofitting it everywhere at once. Existing call sites that rely on a numeric distance should be identified and pinned with a test before refactoring.
Compatibility: Additive public API (distance() accessor, Distance class) and a stricter error path. The main compatibility question is the return type of distance(); if it changed from scalar to object, treat this as a soft breaking change for anything that does arithmetic on the result or serialises it directly. The new exception could also surface in existing tests that previously asserted on a different failure mode.
Sequencing:
distance() return-type question and any newly thrown exceptions.nearestFirst() without nearby().Distance incrementally in new feature work.Maintenance: Low ongoing burden. Pin with a caret constraint and review minor releases; the surface area is small. Budget a small amount of time per upgrade to read the changelog, since the package's test coverage and CI guarantees are not evidenced here.
Support: The principal operational risk is project sustainability rather than the code itself. A single-maintainer or low-activity repository means bug turnaround and Laravel-major compatibility updates are not guaranteed. For anything business-critical, plan a fork-or-replace contingency and keep the geospatial logic isolated behind a thin application-level service so it can be swapped.
Scaling: Haversine filtering generally computes a distance expression over a candidate row set; without a bounding-box prefilter on latitude/longitude (or a spatial index), query cost grows with table size and the sort becomes expensive. Verify that nearby() generates a prefilter rather than a full scan, and benchmark against realistic row counts before committing. For large datasets, treat this package as a convenience layer over a query that still needs proper indexing.
Failure modes:
nearestFirst() without nearby()) — now fails loudly, which is an improvement, but the ordering dependency remains a design constraint to document internally.Distance object is returned in an API payload.Ramp-up: Very low. The API is small and intention-revealing, and the new explicit exception measurably shortens the debugging loop for the most likely misuse. A developer unfamiliar with the package should be productive within an hour, provided the unit conventions and the SQL-vs-PHP computation model are documented in the team's internal notes.
How can I help you explore Laravel packages today?