PHP code example of ariadata / laravel-clickhouse

1. Go to this page and download the library: Download ariadata/laravel-clickhouse 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/ */

    

ariadata / laravel-clickhouse example snippets


'connections' => [
    // ...

    'clickhouse' => [
        'driver' => 'clickhouse',
        'host' => env('CLICKHOUSE_HOST', '127.0.0.1'),
        'port' => env('CLICKHOUSE_PORT', 8123),
        'username' => env('CLICKHOUSE_USERNAME', 'default'),
        'password' => env('CLICKHOUSE_PASSWORD', ''),
        'database' => env('CLICKHOUSE_DATABASE', 'default'),
        'settings' => [
            'readonly' => env('CLICKHOUSE_READONLY', 0),
            'max_execution_time' => env('CLICKHOUSE_MAX_EXECUTION_TIME', 60),
        ],
    ],
],



namespace App\Models;

use Ariadata\LaravelClickHouse\Database\ClickHouseModel;

class AnalyticsEvent extends ClickHouseModel
{
    protected $connection = 'clickhouse';

    protected $table = 'analytics_events';

    public $timestamps = false;

    protected function casts(): array
    {
        return [
            'properties' => \Ariadata\LaravelClickHouse\Casts\ClickHouseJson::class,
            'tags' => \Ariadata\LaravelClickHouse\Casts\ClickHouseArray::class,
        ];
    }
}

use Ariadata\LaravelClickHouse\Facades\ClickHouse;

$rows = ClickHouse::select('SELECT * FROM analytics_events WHERE user_id = ?', [1]);

ClickHouse::healthCheck();
ClickHouse::getServerVersion();

ClickHouse::table('analytics_events')
    ->where('created_at', '>=', today())
    ->get();
bash
php artisan vendor:publish --provider="Ariadata\LaravelClickHouse\ClickHouseServiceProvider" --tag="clickhouse-config"