PHPackages                             dmgctrlr/lara-osrm - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. dmgctrlr/lara-osrm

ActiveLibrary[API Development](/categories/api)

dmgctrlr/lara-osrm
==================

v2.2(4y ago)8724↓100%6[2 issues](https://github.com/dmgctrlr/lara-osrm/issues)[1 PRs](https://github.com/dmgctrlr/lara-osrm/pulls)MITPHPPHP ^7.3|^8CI failing

Since Feb 15Pushed 4y ago2 watchersCompare

[ Source](https://github.com/dmgctrlr/lara-osrm)[ Packagist](https://packagist.org/packages/dmgctrlr/lara-osrm)[ Docs](https://github.com/dmgctrlr/lara-osrm)[ RSS](/packages/dmgctrlr-lara-osrm/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (4)Versions (12)Used By (0)

Wrapper around OSRM for Laravel
===============================

[](#wrapper-around-osrm-for-laravel)

[![Build Status](https://camo.githubusercontent.com/191358bb8d6b3ff5e8584f19a0682d8321e94a255fe4b14e9cf66f62a3618763/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f646d676374726c722f6c6172612d6f73726d2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.com/dmgctrlr/lara-osrm)[![Latest Version on Packagist](https://camo.githubusercontent.com/1c9aaaa1e498336c61d774fe5b6b348fc8a62746b799cf11709bac31c5d3d138/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646d676374726c722f6c6172612d6f73726d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dmgctrlr/lara-osrm)[![PHP Version Minimum](https://camo.githubusercontent.com/208ad7a2c0e59d70a6552c75e665d3a60caa8d0039471c73ed1451c271b2a109/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646d676374726c722f6c6172612d6f73726d2e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/208ad7a2c0e59d70a6552c75e665d3a60caa8d0039471c73ed1451c271b2a109/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646d676374726c722f6c6172612d6f73726d2e7376673f7374796c653d666c61742d737175617265)[![License](https://camo.githubusercontent.com/1437b32a66abe632eaff9c0d0e3e141c3ab54c8dd9a51a92aa627d7fef44c0f4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f646d676374726c722f6c6172612d6f73726d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dmgctrlr/lara-osrm)

This package is a simple wrapper for querying OSRM. It assumes you have an OSRM v5.x server available. It supports route, nearest, table, match, and trip services. Driving is the only profile currently supported.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require dmgctrlr/lara-osrm
```

Publish the config file (config/lara-osrm.config)

```
php artisan vendor:publish --tag="config" --provider="Dmgctrlr\LaraOsrm\LaraOsrmServiceProvider"
```

You can overwrite the defaults in your `.env` file too:

```
OSRM_HOST=localhost
OSRM_PORT=5000
OSRM_VERSION=v1
```

Usage
-----

[](#usage)

Getting the Request Service
---------------------------

[](#getting-the-request-service)

There are a few ways to get the request service, depending on your preferences and situation.

### Direct Creation

[](#direct-creation)

You can create them directly - passing an array (including 'host' and 'port' keys if you want to overwrite reading from `config()`

```
// Create a ServiceRequest based on the service you want: RouteServiceRequest, MatchServiceRequest, TripServiceRequest
use Dmgctrlr\LaraOsrm\RouteServiceRequest;

// Pass config to overwrite the defaults and your laravel config/lara-osrm.php
$config = [
    'host' => 'localhost', // Hostname of your OSRM server
    'port' => 5000, // Port for your OSRM server
];
$request = new RouteServiceRequest($config);
```

### Dependency Injection

[](#dependency-injection)

LaraOSRM registers with Laravel's dependency injector - so if you're using LaraOSRM in a controller, job or similar you can simply add it as a requirement. It will be setup using the config settings defined in `config/lara-osrm.php` and/or `.env`

```
