PHP code example of rikodev / laravel-influxdb2

1. Go to this page and download the library: Download rikodev/laravel-influxdb2 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rikodev / laravel-influxdb2 example snippets


'providers' => [
    RikoDEV\InfluxDB\Providers\ServiceProvider::class,
],

'aliases' => [
    'InfluxDB' => RikoDEV\InfluxDB\Facades\InfluxDB::class,
],

use RikoDEV\InfluxDB\Facades\InfluxDB;

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

// Query data
$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();

use RikoDEV\InfluxDB\Facades\InfluxDB;
use InfluxDB2\Point;

// Get the write client
$writeApi = InfluxDB::createWriteApi();

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

InfluxDB::close();
ini
INFLUXDB_HOST=localhost
INFLUXDB_PORT=8086
INFLUXDB_TOKEN=
INFLUXDB_BUCKET=
INFLUXDB_ORG=
sh
php artisan vendor:publish --provider="RikoDEV\InfluxDB\Providers\ServiceProvider"