Skip to content

A service made to provide, set up and use the library from influxdata/influxdb-client-php in Laravel.

Notifications You must be signed in to change notification settings

Doclassif/laravel-influxdb2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Register service provider.

```php
'providers' => [
//  ...
    Kali\InfluxDB\Providers\ServiceProvider::class,
]
```
```php
'aliases' => [
//  ...
    'InfluxDB' => Kali\InfluxDB\Facades\InfluxDB::class,
]
```
  • Define env variables to connect to InfluxDB
INFLUXDB_HOST=
INFLUXDB_PORT=
INFLUXDB_TOKEN=
INFLUXDB_BUCKET=
INFLUXDB_ORG=
  • Write this into your terminal inside your project
    php artisan vendor:publish
    
    

Reading Data

<?php
use Kali\InfluxDB\Facades\InfluxDB;

// Get query client
$queryApi = InfluxDB::createQueryApi();

// Synchronously executes query and return result as unprocessed String
$result = $queryApi->queryRaw(
    "from(bucket: \"my-bucket\")
                |> range(start: 0)
                |> filter(fn: (r) => r[\"_measurement\"] == \"weather\"
                                 and r[\"_field\"] == \"temperature\"
                                 and r[\"location\"] == \"Sydney\")"
);

InfluxDB::close();

Writing Data

<?php

$writeApi = InfluxDB::createWriteApi();

// create an array of points
$result = $writeApi->write([
    Point::measurement("blog_posts")
      ->addTag("post_id", $post->id)
      ->addField("likes", 6)
      ->addField("comments", 3)
      ->time(time())
]);

InfluxDB::close();

About

A service made to provide, set up and use the library from influxdata/influxdb-client-php in Laravel.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages