PHPackages                             mr-wolf-gb/traccar - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. mr-wolf-gb/traccar

ActiveLibrary[HTTP &amp; Networking](/categories/http)

mr-wolf-gb/traccar
==================

Traccar GPS server

1.1.1(1mo ago)139053MITPHPPHP ^8.1CI passing

Since Feb 13Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/mr-wolf-gb/traccar)[ Packagist](https://packagist.org/packages/mr-wolf-gb/traccar)[ Docs](https://github.com/mr-wolf-gb/traccar)[ GitHub Sponsors](https://github.com/mr-wolf-gb)[ Patreon](https://www.patreon.com/wolf_development)[ RSS](/packages/mr-wolf-gb-traccar/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (5)Dependencies (23)Versions (6)Used By (0)

Traccar GPS server
==================

[](#traccar-gps-server)

[![Latest Version on Packagist](https://camo.githubusercontent.com/fa81f0513e813f76edfb86d7f9c55080098325f531e7bc969cf2cd5d8ef1a7f1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d722d776f6c662d67622f747261636361722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mr-wolf-gb/traccar)[![Total Downloads](https://camo.githubusercontent.com/0cfd7b9270dd178bc9aac65260deb4311da524b97bd6e7287e24a1902751e8db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d722d776f6c662d67622f747261636361722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mr-wolf-gb/traccar)[![Latest Unstable Version](https://camo.githubusercontent.com/4826af6050be8376304aaf29f41e532dc234845d71d4244fa4b1aeefb8250e44/687474703a2f2f706f7365722e707567782e6f72672f6d722d776f6c662d67622f747261636361722f762f756e737461626c653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mr-wolf-gb/traccar)[![License](https://camo.githubusercontent.com/db6338f8348bb8167e378ffa55b31243ab00cf0cd824bd125ad89131c3c2a003/687474703a2f2f706f7365722e707567782e6f72672f6d722d776f6c662d67622f747261636361722f6c6963656e73653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mr-wolf-gb/traccar)[![PHP Version Require](https://camo.githubusercontent.com/7452af395e9e23340e5f35335fa030b13a2ac6e68509948dcb14149429096ade/687474703a2f2f706f7365722e707567782e6f72672f6d722d776f6c662d67622f747261636361722f726571756972652f7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mr-wolf-gb/traccar)

This Laravel package serves as a seamless integration tool, empowering developers to effortlessly interact with Traccar servers through their robust API. Traccar, a powerful GPS tracking platform, becomes more accessible than ever as this package streamlines communication between your Laravel application and the Traccar server, offering a wide range of functionalities and capabilities. Whether you're retrieving real-time location data, managing devices, or leveraging advanced tracking features, this package simplifies the process, enhancing the efficiency and extensibility of your Laravel projects.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Features and Usage](#features-and-usage)
    - [Multi-users and servers](#multi-users-and-servers)
    - [Authentication](#authentication)
    - [Available resources](#available-resources)
        - [Server](#server)
        - [Session](#session)
        - [User](#user)
        - [Group](#group)
        - [Device](#device)
        - [Geofence](#geofence)
        - [Notification](#notification)
        - [Position](#position)
        - [Event](#event)
        - [Driver](#driver)
        - [Report](#report)
        - [Command](#command)
        - [Order](#order)
        - [Permission](#permission)
        - [Share](#share)
        - [Statistic](#statistic)
        - [Calendar](#calendar)
        - [Computed Attribute](#computed-attribute)
        - [Maintenance](#maintenance)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

🔧 Required PHP version
----------------------

[](#wrench-required-php-version)

VersionPhp Version1.1.1^8.11.1.0^8.11.0.0^8.1Installation
------------

[](#installation)

You can install the package via composer:

```
composer require mr-wolf-gb/traccar
```

You can publish the config and migration:

```
php artisan vendor:publish --provider="MrWolfGb\Traccar\TraccarServiceProvider"
```

Set Traccar server information in your `.env` file:

```
TRACCAR_BASE_URL="http://localhost:8082/"
TRACCAR_SOCKET_URL="ws://localhost:8082/api/socket"
TRACCAR_SOCKET_COOKIE_ENABLED=true
TRACCAR_SOCKET_COOKIE_DOMAIN=
TRACCAR_SOCKET_COOKIE_SAME_SITE="lax"
TRACCAR_SOCKET_COOKIE_SECURE=false
TRACCAR_SOCKET_COOKIE_HTTP_ONLY=true
TRACCAR_USERNAME="admin@traccar.local"
TRACCAR_PASSWORD="password"
TRACCAR_TOKEN="RzBFAiEA84hXSL6uV6FQyBX0_Ds1a6NMcSC..."
# auto uses TRACCAR_TOKEN as Bearer auth when it has a value, otherwise falls back to Basic auth
TRACCAR_AUTH_METHOD="auto" # auto, token, basic
```

✨ Features and Usage
--------------------

[](#-features-and-usage)

#### Multi-users and servers

[](#multi-users-and-servers)

```
// By default, the service uses .env credentials. You can also override them manually.
// Inject service as a public variable in a controller.
public function __construct(public TraccarService $traccarService)
{
    $this->traccarService->setEmail("user1@traccar.local");
    $this->traccarService->setPassword("password");
    $this->traccarService->setBaseUrl("http://localhost:8082/");
    $this->traccarService->setToken("RzBFAiEA84hXSL6uV6FQyBX0_Ds1a6NMcSC...");
    $this->traccarService->setAuthMethod("auto"); // auto, token, basic
}
// Or inject directly in a controller method.
public function index(TraccarService $traccarService)
{
    //...
}
```

#### Authentication

[](#authentication)

The package supports Traccar Basic authentication and API token authentication. By default, `TRACCAR_AUTH_METHOD=auto` uses `TRACCAR_TOKEN` as a Bearer token when it has a value. If no token is configured, requests fall back to Basic authentication with `TRACCAR_USERNAME` and `TRACCAR_PASSWORD`.

Use `TRACCAR_AUTH_METHOD=basic` when you want to force Basic authentication even if a token exists. Use `TRACCAR_AUTH_METHOD=token` when you want token authentication only.

```
$traccarService->setToken('token-from-traccar');
$traccarService->setAuthMethod('token');

// Force Basic auth for every authorized request.
$traccarService->setAuthMethod('basic');
```

#### Available resources

[](#available-resources)

- #### *Server*

    [](#server)

Model : **[Server Model](src/Models/Server.php)**

```
public function index(TraccarService $traccarService)
{
    $serverRepo = $traccarService->serverRepository();

    $serverRepo->checkHealth();
    $serverRepo->fetchTimezones();
    $serverRepo->reverseGeocode(latitude: 36.8065, longitude: 10.1815);
    $serverRepo->fetchCacheDiagnostics();
    $serverRepo->triggerGarbageCollection();
    $serverRepo->rebootServer();

    $srv = $serverRepo->fetchServerInformation(); // returns Server model
    $serverRepo->updateServerInformation(server: $srv);

    $serverRepo->uploadServerFile(path: 'example/file.txt', localFile: storage_path('app/file.txt'));
}
```

- #### *Session*

    [](#session)

Model : **[Session Model](src/Models/Session.php)**

```
public function index(TraccarService $traccarService)
{
    $sessionRepo = $traccarService->sessionRepository();

    $session = $sessionRepo->createNewSession(); // POST /session with configured username and password
    $session = $sessionRepo->fetchSessionInformation(); // GET /session?token=... using TRACCAR_TOKEN
    $session = $sessionRepo->fetchSessionInformationWithToken('session-token');
    $session = $sessionRepo->fetchSessionInformationWithCredentials(); // alias of createNewSession()
    $token = $sessionRepo->generateSessionToken(expiration: now()->addDay()->toIso8601String());
    $sessionRepo->revokeSessionToken(token: $token);
    $sessionRepo->fetchOpenIdAuth();
    $sessionRepo->openIdCallback(['code' => 'openid-code']);
    $sessionRepo->closeSession();
}
```

- #### *User*

    [](#user)

Model : **[User Model](src/Models/User.php)**

```
public function index(TraccarService $traccarService)
{
    $userRepo = $traccarService->userRepository();

    $list = $userRepo->fetchListUsers();
    $user = $userRepo->createUser(
        name: 'test',
        email: 'test@test.local',
        password: 'test'
    );
    $user = $userRepo->createNewUser(new User([
        'name' => 'test',
        'email' => 'test@test.local',
        'password' => 'test',
    ]));

    $user = $userRepo->updateUser(user: $user);
    $userRepo->deleteUser(user: $user);
    $userRepo->assignUserDevice(user: 1, device: 1);
    $userRepo->removeUserDevice(user: 1, device: 1);
    $secret = $userRepo->generateTotpSecret();
}
```

- #### *Group*

    [](#group)

Model : **[Group Model](src/Models/Group.php)**

```
public function index(TraccarService $traccarService)
{
    $groupRepo = $traccarService->groupRepository();
    // Get list of groups
    $list = $groupRepo->fetchListGroups();
    // Create new group
    $group = $groupRepo->createGroup(name: 'test-group');
    // Create new group with Model : MrWolfGb\Traccar\Models\Group
    $group = $groupRepo->createNewGroup(group: new Group(['name' => 'test']));
    // Update group
    $user = $groupRepo->updateGroup(group: $group);
    // Delete group : int|Group $group
    $groupRepo->deleteGroup(group: $group);
}
```

- #### *Device*

    [](#device)

Model : **[Device Model](src/Models/Device.php)**

```
public function index(TraccarService $traccarService)
{
    $deviceRepo = $traccarService->deviceRepository();
    // Get list of devices
    $list = $deviceRepo->fetchListDevices();
    // Get user devices
    $list = $deviceRepo->getUserDevices(userId: 1);
    // Get device by id
    $device = $deviceRepo->getDeviceById(deviceId: 1);
    // Get device by uniqueId
    $device = $deviceRepo->getDeviceByUniqueId(uniqueId: 123456);
    // Create new device
    $device = $deviceRepo->createDevice(name: 'test', uniqueId: '123456789');
    // Create new device with Model : MrWolfGb\Traccar\Models\Device
    $device = $deviceRepo->createNewDevice(device: new Device([
        'name' => 'test-device',
        'uniqueId' => '123456789-d1-device',
    ]));
    // Update device
    $device = $deviceRepo->updateDevice(device: $device);
    // Delete device : int|Device $device
    $deviceRepo->deleteDevice(device: $device);
    // Upload or update device image
    $imageName = $deviceRepo->uploadDeviceImage(device: $device, path: storage_path('app/device.png'));
    // Update total distance and hours
    $deviceRepo->updateTotalDistanceAndHoursOfDevice(device: $device, totalDistance: 100, hours: 10);
    // Assign device to geofence : int|Device $device, int|Geofence $geofence
    $deviceRepo->assignDeviceGeofence(device: $device, geofence: $geofence);
    // Remove device from geofence : int|Device $device, int|Geofence $geofence
    $deviceRepo->removeDeviceGeofence(device: $device, geofence: $geofence);
    // Assign device to notification : int|Device $device, int|Notification $notification
    $deviceRepo->assignDeviceNotification(device: $device, notification: $notification);
    // Remove device from notification : int|Device $device, int|Notification $notification
    $deviceRepo->removeDeviceNotification(device: $device, notification: $notification);
}
```

- #### *Geofence*

    [](#geofence)

Model : **[Geofence Model](src/Models/Geofence.php)**

```
public function index(TraccarService $traccarService)
{
    $geofenceRepo = $traccarService->geofenceRepository();
    // Get list of geofences
    $list = $geofenceRepo->fetchListGeofences();
    // Get geofence
    $geofence = $geofenceRepo->createGeofence(
        name: 'test-geofence',
        area: 'POLYGON ((34.55602185173028 -18.455295134508617, 37.67183427726626 -18.13110040602976, 34.98211925933252 -14.500119447061167, 34.55602185173028 -18.455295134508617))',
        description: 'test'
    );
    // Create new geofence with Model : MrWolfGb\Traccar\Models\Geofence
    $geofence = $geofenceRepo->createNewGeofence( geofence: new Geofence([
        'name' => 'test-geofence',
        'area' => 'LINESTRING (38.06472440318089 -26.49821693459276, 38.4968396008517 -24.64860674974679, 37.297972401178825 -23.72380165732423, 38.099388220592346 -23.37149495544884)',
        'description' => 'test'
    ]));
    // Update geofence
    $geofence = $geofenceRepo->updateGeofence(geofence: $geofence);
    // Delete geofence : int|Geofence $geofence
    $geofenceRepo->deleteGeofence(geofence: $geofence);
}
```

- #### *Notification*

    [](#notification)

Model : **[Notification Model](src/Models/Notification.php)**

```
public function index(TraccarService $traccarService)
{
    $notificationRepo = $traccarService->notificationRepository();
    // Get list of notifications
    $list = $notificationRepo->fetchListNotifications();
    // Create new notification
    $notification = $notificationRepo->createNotification(
        type: 'alarm',
        notificators: ['web'],
        always: true
    );
    // Create new notification with Model : MrWolfGb\Traccar\Models\Notification
    $notification = $notificationRepo->createNewNotification(new Notification([
        'type' => NotificationType::ALARM->value,
        'notificators' => implode(',', [
            NotificatorType::WEB->value,
            NotificatorType::COMMAND->value
        ]),
        'always' => false,
        'commandId' => 1, // required if notificator is/contains command
    ]));
    // Update notification
    $notification = $notificationRepo->updateNotification(notification: $notification);
    // Delete notification : int|Notification $notification
    $notificationRepo->deleteNotification(notification: $notification);
    // Get notification types from Traccar server
    $list = $notificationRepo->fetchNotificationTypes();
    // Send test notification
    $notificationRepo->sendTestNotification();
    // Send custom notification through a notificator
    $notificationRepo->sendCustomNotification(
        notificator: NotificatorType::WEB->value,
        payload: ['message' => 'Hello from Laravel'],
        userId: [1, 2] // optional
    );
}
```

- #### *Position*

    [](#position)

Model : **[Position Model](src/Models/Position.php)**

```
public function index(TraccarService $traccarService)
{
    $positionRepo = $traccarService->positionRepository();
    // Get list of positions
    $list = $positionRepo->fetchListPositions(
        from: now()->subHours(1),
        to: now(),
        id: [1, 2, 3] // optional
    );
    // Delete positions of device : int|Device $device
    $positionRepo->deletePositions(
        device: 1,
        from: now()->subHours(1),
        to: now()
    );
    // Delete one position
    $positionRepo->deletePosition(id: 1);
    // Export positions
    $kml = $positionRepo->exportPositionsKml([
        'deviceId' => 1,
        'from' => now()->subHours(1)->toIso8601String(),
        'to' => now()->toIso8601String(),
    ]);
    $csv = $positionRepo->exportPositionsCsv([
        'deviceId' => 1,
        'from' => now()->subHours(1)->toIso8601String(),
        'to' => now()->toIso8601String(),
    ]);
    $gpx = $positionRepo->exportPositionsGpx([
        'deviceId' => 1,
        'from' => now()->subHours(1)->toIso8601String(),
        'to' => now()->toIso8601String(),
    ]);
    // OsmAnd
    $positionRepo->OsmAnd(uniqueId: "1234-d1", temperature: "21.5", abc: "def");
}
```

- #### *Event*

    [](#event)

Model : **[Event Model](src/Models/Event.php)**

```
public function index(TraccarService $traccarService)
{
    // Get specific event details
    $event = $traccarService->eventRepository()->fetchEventInformation(eventID: 1);
}
```

- #### *Driver*

    [](#driver)

Model : **[Driver Model](src/Models/Driver.php)**

```
public function index(TraccarService $traccarService)
{
    $driverRepo = $traccarService->driverRepository();
    // Get list of drivers
    $list = $driverRepo->fetchListDrivers();
    // Create new driver
    $driver = $driverRepo->createDriver(
        name: 'test-driver',
        uniqueId: '123456789-d1-driver'
    );
    // Create new driver with Model : MrWolfGb\Traccar\Models\Driver
    $driver = $driverRepo->createNewDriver( new Driver([
      'name' => 'test-driver',
      'uniqueId' => '123456789-d1-driver'
    ]));
    // Update driver
    $driver = $driverRepo->updateDriver(driver: $driver);
    // Delete driver : int|Driver $driver
    $driverRepo->deleteDriver(driver: $driver);
}
```

- #### *Report*

    [](#report)

Model : **[Report Model](src/Models/Report.php)**

```
public function index(TraccarService $traccarService)
{
    $reportRepo = $traccarService->reportRepository();
    // Get route report for specific device
    $list = $reportRepo->reportRoute(
        from:  now()->subHours(value: 3),
        to: now(),
        deviceId: 1
    );
    // Get events report
    $list = $reportRepo->reportEvents(
        from:  now()->subHours(value: 3),
        to: now(),
        deviceId: 1,
        type: 'engine' // optional, by default 'allEvents'
    );
    // Get summary report
    $list = $reportRepo->reportSummary(
        from:  now()->subHours(value: 3),
        to: now(),
        deviceId: [1,2],
        //groupId: [1,2], // optional
        //daily: true // optional
    );
    // Get trips report
    $list = $reportRepo->reportTrips(
        from:  now()->subHours(value: 3),
        to: now(),
        deviceId: 1
    );
    // Get stops report
    $list = $reportRepo->reportStops(
        from:  now()->subHours(value: 3),
        to: now(),
        deviceId: 1
    );
    // Get combined report
    $list = $reportRepo->reportCombined(
        from:  now()->subHours(value: 3),
        to: now(),
        deviceId: [1,2],
        //groupId: [1,2], // optional
    );
    // Get geofences report
    $list = $reportRepo->reportGeofences(
        from: now()->subHours(value: 3),
        to: now(),
        deviceId: [1, 2],
        //groupId: [1,2], // optional
    );
}
```

- #### *Command*

    [](#command)

These endpoints return `Command` and `CommandType` models, or collections of those models.

```
public function index(TraccarService $traccarService)
{
    $commandRepo = $traccarService->commandRepository();

    $list = $commandRepo->fetchListCommands(all: true, deviceId: 1);
    $types = $commandRepo->fetchCommandTypes(deviceId: 1);
    $supported = $commandRepo->fetchSupportedCommands(deviceId: 1);
    $command = $commandRepo->createCommand([
        'deviceId' => 1,
        'type' => 'custom',
        'attributes' => ['data' => 'status'],
    ]);
    $command = $commandRepo->updateCommand(id: $command->id, command: $command);
    $sent = $commandRepo->dispatchCommand(command: [
        'deviceId' => 1,
        'type' => 'custom',
        'attributes' => ['data' => 'status'],
    ]);
    $commandRepo->deleteCommand(id: $command->id);
}
```

- #### *Order*

    [](#order)

```
public function index(TraccarService $traccarService)
{
    $orderRepo = $traccarService->orderRepository();

    $list = $orderRepo->fetchListOrders(all: true, limit: 20);
    $order = $orderRepo->createOrder(['description' => 'Delivery order']);
    $order = $orderRepo->updateOrder(id: $order->id, order: $order);
    $orderRepo->deleteOrder(id: $order->id);
}
```

- #### *Permission*

    [](#permission)

Use this repository when you need permission links that are not covered by convenience methods such as `assignUserDevice`.

```
public function index(TraccarService $traccarService)
{
    $permissionRepo = $traccarService->permissionRepository();

    $links = $permissionRepo->fetchPermissions(['userId' => 1]);
    $permissionRepo->linkPermission(['userId' => 1, 'deviceId' => 1]);
    $permissionRepo->unlinkPermission(['userId' => 1, 'deviceId' => 1]);
}
```

- #### *Share*

    [](#share)

```
public function index(TraccarService $traccarService)
{
    $shareRepo = $traccarService->shareRepository();

    $deviceToken = $shareRepo->shareDevice(
        deviceId: 1,
        expiration: now()->addDay()->toIso8601String()
    );
    $groupToken = $shareRepo->shareGroup(
        groupId: 1,
        expiration: now()->addDay()->toIso8601String()
    );
}
```

- #### *Statistic*

    [](#statistic)

```
public function index(TraccarService $traccarService)
{
    $statistics = $traccarService->statisticRepository()->fetchServerStatistics(
        from: now()->subDay()->toIso8601String(),
        to: now()->toIso8601String()
    );
}
```

- #### *Calendar*

    [](#calendar)

```
public function index(TraccarService $traccarService)
{
    $calendarRepo = $traccarService->calendarRepository();

    $list = $calendarRepo->fetchListCalendars(all: true);
    $calendar = $calendarRepo->createCalendar(['name' => 'Work days']);
    $calendar = $calendarRepo->updateCalendar(id: $calendar->id, calendar: $calendar);
    $calendarRepo->deleteCalendar(id: $calendar->id);
}
```

- #### *Computed Attribute*

    [](#computed-attribute)

```
public function index(TraccarService $traccarService)
{
    $attributeRepo = $traccarService->attributeRepository();

    $list = $attributeRepo->fetchListComputedAttributes(all: true, deviceId: 1);
    $attribute = $attributeRepo->createComputedAttribute([
        'description' => 'Ignition status',
        'attribute' => 'ignition',
        'expression' => 'io1',
        'type' => 'boolean',
    ]);
    $attribute = $attributeRepo->updateComputedAttribute(id: $attribute->id, attribute: $attribute);
    $attributeRepo->deleteComputedAttribute(id: $attribute->id);
}
```

- #### *Maintenance*

    [](#maintenance)

```
public function index(TraccarService $traccarService)
{
    $maintenanceRepo = $traccarService->maintenanceRepository();

    $list = $maintenanceRepo->fetchListMaintenance(all: true, deviceId: 1);
    $maintenance = $maintenanceRepo->createMaintenance([
        'name' => 'Oil change',
        'type' => 'totalDistance',
        'period' => 10000,
    ]);
    $maintenance = $maintenanceRepo->updateMaintenance(id: $maintenance->id, maintenance: $maintenance);
    $maintenanceRepo->deleteMaintenance(id: $maintenance->id);
}
```

### Commands

[](#commands)

This command stores devices in the local database using the published migration.

```
php artisan traccar:sync
```

Or

```
php artisan traccar:sync-devices
```

### Listen to Traccar websocket with PHP

[](#listen-to-traccar-websocket-with-php)

The package includes an Artisan command that connects to the Traccar websocket with a valid `JSESSIONID` cookie retrieved from `SessionResources::getCookies()`.

```
php artisan traccar:listen --log
```

You can override the websocket URL when needed:

```
php artisan traccar:listen --ws=ws://127.0.0.1:8082/api/socket --log
```

The command uses [`phrity/websocket`](https://phrity.sirn.se/websocket), the maintained package for the `sirn-se/websocket-php` websocket client.

### Browser websocket access

[](#browser-websocket-access)

Browsers cannot manually set the `Cookie` header on `new WebSocket(...)`. The cookie must already be stored by the browser, then the browser sends it automatically during the websocket handshake.

Use the `TraccarSession` middleware on the page that opens the websocket. It retrieves the current Traccar session cookie and adds it to the HTTP response as `Set-Cookie`.

```
// route web.php
Route::get('/', [HomeController::class, 'index'])->middleware('TraccarSession');
```

Then open the websocket without adding `?session=`:

```
// blade view
const socket = new WebSocket("{{ config('traccar.websocket_url') }}");
socket.onerror = (error) => {
    console.log('socket error: ', error)
}
socket.onmessage = function (event) {
    const data = JSON.parse(event.data);
    console.log('socket message : ', data)
}
```

This works when Laravel and the Traccar websocket are on the same browser-facing site.

Example `.env` for plain HTTP:

```
TRACCAR_BASE_URL="http://127.0.0.1:8082/"
TRACCAR_SOCKET_URL="ws://app.example.com/api/socket"
TRACCAR_SOCKET_COOKIE_SECURE=false
```

Example `.env` for HTTPS:

```
TRACCAR_BASE_URL="http://127.0.0.1:8082/"
TRACCAR_SOCKET_URL="wss://app.example.com/api/socket"
TRACCAR_SOCKET_COOKIE_SECURE=true
```

#### External JavaScript app

[](#external-javascript-app)

If your JavaScript page is hosted on another domain, use a Traccar session token in the websocket URL. This avoids the browser limitation that prevents JavaScript from setting the websocket `Cookie` header manually.

Generate a token from Laravel:

```
$token = app(\MrWolfGb\Traccar\Services\TraccarService::class)
    ->sessionRepository()
    ->generateSessionToken(now()->addHour()->toIso8601String());
```

Then pass that token to your external JavaScript app and connect with `?token=`:

```
const traccarDomain = 'tracking.example.com';
const token = 'RjBEAiBHAITAUA_iZnMr4iYJw5jmesXDbkWf8t7qoHezq';
const socketUrl = `wss://${traccarDomain}:8082/api/socket?token=${encodeURIComponent(token)}`;
const socket = new WebSocket(socketUrl);
```

Use `ws://` for plain HTTP Traccar servers and `wss://` for HTTPS. Prefer short-lived session tokens and avoid exposing your permanent API token in browser code.

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Mr.WOLF](https://github.com/mr-wolf-gb)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance90

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~206 days

Total

5

Last Release

46d ago

Major Versions

0.0.1 → 1.0.02024-02-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/15419351feb134ab8ee8e00c4bab3be9f71f32c171a747c9ed6c2ada4d04d772?d=identicon)[gaiththewolf](/maintainers/gaiththewolf)

---

Top Contributors

[![mr-wolf-gb](https://avatars.githubusercontent.com/u/4011175?v=4)](https://github.com/mr-wolf-gb "mr-wolf-gb (45 commits)")[![sayasuhendra](https://avatars.githubusercontent.com/u/4870292?v=4)](https://github.com/sayasuhendra "sayasuhendra (2 commits)")

---

Tags

gps-trackinglaravelrealtimeservicetraccartraccar-apiwebsocketapilaravelgpsTraccar

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mr-wolf-gb-traccar/health.svg)

```
[![Health](https://phpackages.com/badges/mr-wolf-gb-traccar/health.svg)](https://phpackages.com/packages/mr-wolf-gb-traccar)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6942.5M421](/packages/drupal-core-recommended)[dreamfactory/df-core

DreamFactory(tm) Core Components

1652.1k38](/packages/dreamfactory-df-core)[huaweicloud/huaweicloud-sdk-php

Huawei Cloud SDK for PHP

1830.8k2](/packages/huaweicloud-huaweicloud-sdk-php)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

273.0k](/packages/eslazarev-wildberries-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
