Download the PHP package gowelle/laravel-route-matrix without Composer
On this page you can find all versions of the php package gowelle/laravel-route-matrix. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gowelle/laravel-route-matrix
More information about gowelle/laravel-route-matrix
Files in gowelle/laravel-route-matrix
Package laravel-route-matrix
Short Description A Laravel wrapper package for Google Routes API (Compute Routes)
License MIT
Homepage https://github.com/gowelle/laravel-route-matrix
Informations about the package laravel-route-matrix
Laravel Route Matrix
A Laravel wrapper for the Google Routes API with support for route calculation, distance matrices, and waypoint optimization.
Table of Contents
- Features
- Requirements
- Installation
- Quick Start
- Usage
- Basic Route Calculation
- Travel Modes
- Traffic-Aware Routing
- Route Modifiers
- Alternative Routes
- Waypoint Optimization
- Route Matrix
- One to Many
- Many to One
- Many to Many
- Courier Example
- Response Objects
- Eloquent Integration
- Configuration
- Exception Handling
- Testing
- License
Features
- ๐ Multiple Travel Modes - Driving, walking, bicycling, two-wheeler, transit
- ๐ฆ Traffic-Aware Routing - Real-time and historical traffic data
- ๐ Flexible Waypoints - Coordinates, Place IDs, or addresses
- ๐ Distance Matrix - Calculate NรM origin-destination pairs
- ๐ฏ Find Closest - Get closest/fastest destination helpers
- โก Fluent API - Elegant, chainable method calls
- ๐งช Fully Tested - 125+ tests with Pest PHP
Requirements
- PHP 8.3+
- Laravel 11.x, 12.x, or 13.x
- Google Cloud API key with Routes API enabled
Installation
Install the package via Composer:
Publish the configuration file:
Add your Google API key to your .env file:
Quick Start
Usage
Basic Route Calculation
Using Addresses
Using Place IDs
With Intermediate Waypoints
Travel Modes
Traffic-Aware Routing
Route Modifiers
Alternative Routes
Fuel-Efficient Routes
Waypoint Optimization
Departure Time
Extra Computations
Custom Field Mask
Specify which fields to include in the response:
High Quality Polylines
Localization
Complete Example
Eloquent Integration (Routable Trait)
You can make your Eloquent models "routable" by implementing the Routable contract and using the HasRoute trait. This allows you to pass models directly to the API headers.
-
Implement the interface and trait:
-
Use models in route requests:
- Or initiate directly from the model:
Response Caching
To reduce API costs and improve performance, you can enable built-in caching.
- Configure caching in
config/google-routes.php:
When enabled, identical requests (same origin, destination, and options) will be served from the cache for the specified TTL duration.
Route Matrix (Distance Matrix)
The Route Matrix API allows you to calculate distances and travel times between multiple origins and destinations efficiently.
One Origin to Multiple Destinations
Multiple Origins to One Destination
Many to Many (Full Matrix)
Sorting Results
RouteMatrixElement Properties
Each element in the matrix contains:
originIndex- Index of the origin (0-based)destinationIndex- Index of the destination (0-based)distanceMeters- Distance in metersduration- Duration string (e.g., "1234s")condition- Route condition (ROUTE_EXISTS, ROUTE_NOT_FOUND)
Helper methods:
routeExists()- Check if a route was foundgetDurationInSeconds()- Get duration as integergetDistanceInKilometers()- Get distance in kmgetDistanceInMiles()- Get distance in milesgetFormattedDuration()- Get human-readable duration
Real-World Example: Courier Pickup & Delivery
A courier needs to pick up packages from multiple stores and deliver to customers (some packages share the same destination):
Output:
Response Objects
RoutesResponse
The main response object containing:
routes- Collection of Route objectsfallbackInfo- Information about routing fallback (if any)geocodingResults- Geocoding information for address waypoints
Route
Individual route containing:
distanceMeters- Total distance in metersduration- Duration string (e.g., "165s")polyline- Encoded polyline or GeoJSONlegs- Collection of RouteLeg objectsviewport- Map bounding boxrouteLabels- Route type labelswarnings- Route warnings
Helper methods:
getDurationInSeconds()- Get duration as integergetDistanceInKilometers()- Get distance in kmgetDistanceInMiles()- Get distance in milesgetFormattedDuration()- Get human-readable durationisDefaultRoute()- Check if default routeisFuelEfficient()- Check if fuel-efficient route
Configuration
The configuration file (config/google-routes.php) includes:
Exception Handling
The package throws specific exceptions:
Testing
Run the test suite:
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
Credits
- Gowelle
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-route-matrix with dependencies
illuminate/contracts Version ^11.0|^12.0|^13.0
illuminate/http Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0
guzzlehttp/guzzle Version ^7.0