Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use in laravel controller #6

Open
abdullah6066 opened this issue May 19, 2020 · 1 comment
Open

Use in laravel controller #6

abdullah6066 opened this issue May 19, 2020 · 1 comment

Comments

@abdullah6066
Copy link

Can you tell me how can I use it in laravel Controller

@RobinBastiaan
Copy link

The readme does a decent job of explaining how one can use this library, but I hope the following example of a controller method helps:

public function index() {
    $response = DistanceMatrix::license($license)
    ->addOrigin('norwich,gb')
    ->addDestination('52.603669, 1.223785')
    ->request();

    $rows = $response->rows();
    $elements = $rows[0]->elements();
    $element = $element[0];

    $distance = $element->distance();
    $duration = $element->duration();

    return View('my.view'), [
        'distance' => $distance,
        'duration' => $duration,
        // and add any additional variables you want from the API here
    ];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants