PHPackages                             glushkovds/phpclickhouse-laravel - 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. [Database &amp; ORM](/categories/database)
4. /
5. glushkovds/phpclickhouse-laravel

ActiveLibrary[Database &amp; ORM](/categories/database)

glushkovds/phpclickhouse-laravel
================================

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

v2.7.1(1mo ago)2051.5M↓33%51[2 issues](https://github.com/glushkovds/phpclickhouse-laravel/issues)[1 PRs](https://github.com/glushkovds/phpclickhouse-laravel/pulls)2MITPHPPHP &gt;=8.0CI passing

Since Sep 16Pushed 1mo ago4 watchersCompare

[ Source](https://github.com/glushkovds/phpclickhouse-laravel)[ Packagist](https://packagist.org/packages/glushkovds/phpclickhouse-laravel)[ Docs](https://github.com/glushkovds/phpClickHouse-laravel)[ RSS](/packages/glushkovds-phpclickhouse-laravel/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (35)Versions (67)Used By (2)

[![Tests](https://github.com/glushkovds/phpclickhouse-laravel/actions/workflows/test.yml/badge.svg)](https://github.com/glushkovds/phpclickhouse-laravel/actions/workflows/test.yml/badge.svg)

phpClickHouse-laravel
=====================

[](#phpclickhouse-laravel)

Laravel and Lumen adapter for popular ClickHouse libraries:

-  - connections and query execution
-  - query builder

Features
--------

[](#features)

Requires only the PHP cURL extension. PHP 8.0 or higher is supported.

See phpClickHouse features for more details:

Prerequisites
-------------

[](#prerequisites)

- PHP 8.0
- Laravel/Lumen 7+
- ClickHouse server

Installation
------------

[](#installation)

Install via Composer:

```
$ composer require glushkovds/phpclickhouse-laravel
```

Laravel will discover the package service provider automatically.

The package registers a `clickhouse` database connection with sensible defaults. Set only the environment values you need to override:

```
CLICKHOUSE_HOST=localhost
CLICKHOUSE_PORT=8123
CLICKHOUSE_DATABASE=default
CLICKHOUSE_USERNAME=default
CLICKHOUSE_PASSWORD=
CLICKHOUSE_TIMEOUT_CONNECT=2
CLICKHOUSE_TIMEOUT_QUERY=2
CLICKHOUSE_HTTPS=false
CLICKHOUSE_RETRIES=0
CLICKHOUSE_MAX_PARTITIONS_PER_INSERT_BLOCK=300
CLICKHOUSE_FIX_DEFAULT_QUERY_BUILDER=true
```

If your application uses cached configuration, rebuild the cache after changing ClickHouse environment values.

The package registers this connection as `database.connections.clickhouse` automatically when the application does not already define it in `config/database.php`.
If you need to override the defaults or add advanced options, define the connection in `config/database.php`:

```
'connections' => [
    'clickhouse' => [
        'driver' => 'clickhouse',
        'host' => env('CLICKHOUSE_HOST'),
        'port' => (int) env('CLICKHOUSE_PORT', 8123),
        'database' => env('CLICKHOUSE_DATABASE', 'default'),
        'username' => env('CLICKHOUSE_USERNAME', 'default'),
        'password' => env('CLICKHOUSE_PASSWORD', ''),
        'timeout_connect' => env('CLICKHOUSE_TIMEOUT_CONNECT', 2),
        'timeout_query' => env('CLICKHOUSE_TIMEOUT_QUERY', 2),
        'https' => (bool) env('CLICKHOUSE_HTTPS', false),
        'retries' => env('CLICKHOUSE_RETRIES', 0),
        'settings' => [
            'max_partitions_per_insert_block' => 300,
        ],
        'fix_default_query_builder' => true,
    ],
],
```

If you use Lumen or have disabled Laravel package discovery, register the service provider manually:

```
$app->register(\PhpClickHouseLaravel\ClickhouseServiceProvider::class);
```

Usage
-----

[](#usage)

You can use smi2/phpClickHouse functionality directly:

```
/** @var \ClickHouseDB\Client $db */
$db = DB::connection('clickhouse')->getClient();
$statement = $db->select('SELECT * FROM summing_url_views LIMIT 2');
```

See the phpClickHouse documentation for more details:

### Lightweight Eloquent-like model layer

[](#lightweight-eloquent-like-model-layer)

**1.** Add a model

```
