Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laraversine Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

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:

  • Did distance() previously return a scalar? If so, the value object is a behavioural change for existing consumers despite the minor version bump.
  • Is Distance castable/serialisable (JSON, array) and does it expose unit conversion, or is it a thin wrapper over a float?
  • Which unit and earth-radius constant are assumed, and is that configurable?
  • Is the haversine computed in SQL or in PHP after hydration? This determines whether it can be combined with pagination and WHERE clauses efficiently.
  • What Laravel and PHP versions are supported, and is there a published support matrix?
  • Is the package actively maintained (issue response time, release cadence, bus factor)?

Integration Approach

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:

  1. Confirm Laravel/PHP version support against the target application.
  2. Upgrade to v1.1.0 in a non-production environment; run full test suite to catch the distance() return-type question and any newly thrown exceptions.
  3. Add a regression test asserting the explicit error from nearestFirst() without nearby().
  4. Audit JSON resources and API contracts for direct exposure of the distance value.
  5. Adopt Distance incrementally in new feature work.
  6. Only then promote to production, with a rollback pin to v1.0.0 available.

Operational Impact

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:

  • Stateful query scope misuse (nearestFirst() without nearby()) — now fails loudly, which is an improvement, but the ordering dependency remains a design constraint to document internally.
  • Unit confusion (kilometres vs miles, earth-radius constant) producing silently wrong distances.
  • Serialisation surprises when a Distance object is returned in an API payload.
  • Full-table scans at scale causing latency regressions that appear only under production data volumes.
  • Stale package incompatible with a future Laravel major, blocking framework upgrades.

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.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table
siberfx/flysystem-wasabi
hollyit/token-replace
ippanelcom/laravel-sdk
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel