HyperTrack API Integrate into Laravel- Part 2.

hypertrack

In this tutorial, I will explain how to integrate HyperTrack API in laravel.

Generally, HyperTrack API uses for tracking user location and gives information of like current user location, city, latitude and longitude, device and device OS etc.

Just Follow the Previous Tutorial HyperTrack API Integrate into Laravel- Part 1. and Take a look of first two-step and also copy code of third Step.


Step 1: Create a Controller in Laravel

So terminal and put the below command

php artisan make:controller Track/TrackController

Aftre the create a controller put the below code:

<?php

namespace App\Http\Controllers\Track;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Http;

class TrackingController extends Controller{
    public function index(Request $request){
        $client = new \GuzzleHttp\Client();
        $device_id = "Enter Your Device ID";
        $res = $client->request('GET', 
          'https://v3.api.hypertrack.com/devices?$device_id', [
           'auth' => [
              'Enter your Account Key', 
              'Enter your Secret Key'
            ],
        ]);
       echo $res->getStatusCode().'<br>';
       echo $res->getHeader('content-type')[0].'<br>';
       echo $res->getBody();
       return view('track.index'); 
    }
public function startTrack(Request $request){
    $client = new \GuzzleHttp\Client();
    $device_id = 'Enter Your Device ID';
    /*Tracking Your Devices*/
    $res = $client->post('https://v3.api.hypertrack.com/devices?$device_id/start', [
		    'auth' => [
		        'Enter your Account Key', 
		        'Enter your Secret Key'
		    ],
		]);
return view('track.trackstart);
	}
public function stopTrack(Request $request){
    $client = new \GuzzleHttp\Client();
    $device_id = 'Enter Your Device ID';
    /*Tracking Your Devices*/
    $res = $client->post('https://v3.api.hypertrack.com/devices?$device_id/stop', [
		    'auth' => [
		        'Enter your Account Key', 
		        'Enter your Secret Key'
		    ],
		]);
return view('track.trackstop');
	}

Step 4: Create A Route.

Open Your web.php and put the below code:

Route::get('/track','Track\TrackingController@index')->name('track');
Route::get('/trackstart','Track\TrackingController@startTrack')->name('trackstart');
Route::get('/trackstop','Track\TrackingController@stopTrack')->name('trackstop');

Step 5: Create a Blade File

Create folder name is a track and inside track folder create Blade file name is index.blade.php and copy the below code:

@extends('web.yield')
@section('content')
<br>
<br>
<div class="container">
    <h2 class="text-center">Device Tracking System</h2>
    <br>
    <div class="text-center">
        <meta name="csrf-token" content="{{ csrf_token() }}">
        <a href="{{ route('trackstart') }}">Track Start</a>
        <a href="{{ route('trackstop') }}">Track Stop</a>
    </div>
</div>
<br>
@endsection

When clicking on Start and Stop Button it will redirect to a particular page but you don’t get any view but when you click on Start and Stop Button then (If you are login in Application then you will able to show your device tracking system active or not) it will show output.


Stay Home! Stay Safe

About Dhaval Shah

My name is Dhaval Shah. I'm a PHP developer, entrepreneur and CEO of DAG inventions PVT ltd. I live in India and I love to write tutorials and tips that can help other developers. I am a big fan of PHP, Java-script, JQuery, Laravel, WordPress and Bootstrap.
Follow me on Github / Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!