tray-labs / laravel-influxdb
A service made to provide, set up and use the library from influxdata influxphp in Laravel.
v2.0.0
2026-05-12 14:54 UTC
Requires
- illuminate/support: ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
- influxdata/influxdb-client-php: ^3.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0|^11.0
README
A service made to provide, set up and use influxdb-client-php (InfluxDB 2.x) in Laravel.
Installing
composer require tray-labs/laravel-influxdb
Register service provider (pick one of two).
Laravel: inconfig/app.phpfile.Laravel 5.5+ supports package discovery automatically, you should skip this step'providers' => [ TrayLabs\InfluxDB\Providers\ServiceProvider::class, ]
'aliases' => [ 'InfluxDB' => TrayLabs\InfluxDB\Facades\InfluxDB::class, ]
Lumen: inbootstrap/app.phpfile$app->configure('InfluxDB'); $app->register(TrayLabs\InfluxDB\Providers\LumenServiceProvider::class); $app->alias('InfluxDB', TrayLabs\InfluxDB\Facades\InfluxDB::class);
Configuration
Define the env variables to connect to InfluxDB:
INFLUXDB_HOST=localhost INFLUXDB_PORT=8086 INFLUXDB_TOKEN=my-token INFLUXDB_ORG=my-org INFLUXDB_BUCKET=my-bucket INFLUXDB_SSL=false INFLUXDB_VERIFYSSL=false INFLUXDB_TIMEOUT=0
Publish the config file:
php artisan vendor:publish
Writing Data
use InfluxDB2\Point; $writeApi = InfluxDB::createWriteApi(); $point = Point::measurement('test_metric') ->addTag('host', 'server01') ->addTag('region', 'us-west') ->addField('cpucount', 10) ->time(microtime(true)); $writeApi->write($point); $writeApi->close();
Reading Data
$queryApi = InfluxDB::createQueryApi(); $result = $queryApi->query( 'from(bucket:"my-bucket") |> range(start: -1h) |> filter(fn: (r) => r._measurement == "test_metric")' ); foreach ($result as $table) { foreach ($table->records as $record) { echo $record->getField() . ': ' . $record->getValue() . PHP_EOL; } }
License
This project is licensed under the MIT License