PHPackages                             akbarali1/laravel-clickhouse-eloquent - 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. akbarali1/laravel-clickhouse-eloquent

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

akbarali1/laravel-clickhouse-eloquent
=====================================

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

0.2.0.0(2y ago)13.6k—4.2%5[1 PRs](https://github.com/akbarali1/laravel-clickhouse-eloquent/pulls)MITPHPPHP &gt;=8.0

Since Jan 10Pushed 2y ago1 watchersCompare

[ Source](https://github.com/akbarali1/laravel-clickhouse-eloquent)[ Packagist](https://packagist.org/packages/akbarali1/laravel-clickhouse-eloquent)[ Docs](https://github.com/akbarali1/laravel-clickhouse-eloquent)[ RSS](/packages/akbarali1-laravel-clickhouse-eloquent/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (3)Used By (0)

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

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

[](#phpclickhouse-laravel)

Adapter to Laravel and Lumen of the most popular libraries:

-  - for connections and perform queries
-  - good query builder

Features
--------

[](#features)

No dependency, only Curl (support php &gt;=7.1 )

More:

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

[](#prerequisites)

- PHP 7.1, 8.0
- Laravel/Lumen 7+
- Clickhouse server

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

[](#installation)

**1.** Install via composer

```
composer require akbarali1/laravel-clickhouse-eloquent
```

**2.** Add new connection into your config/database.php:

```
'clickhouse' => [
    'driver' => 'clickhouse',
    'host' => env('CLICKHOUSE_HOST'),
    'port' => 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', null),
    'retries' => env('CLICKHOUSE_RETRIES', 0),
    'settings' => [ // optional
        'max_partitions_per_insert_block' => 300,
    ],
],
```

Then patch your .env:

```
CLICKHOUSE_HOST=localhost
CLICKHOUSE_PORT=8123
CLICKHOUSE_DATABASE=default
CLICKHOUSE_USERNAME=default
CLICKHOUSE_PASSWORD=
CLICKHOUSE_TIMEOUT_CONNECT=2
CLICKHOUSE_TIMEOUT_QUERY=2
# only if you use https connection
CLICKHOUSE_HTTPS=true
```

**3.** Add service provider into your config/app.php file providers section:

```
\LaravelClickhouseEloquent\ClickhouseServiceProvider::class,
```

It should be placed *before* App\\Providers\\AppServiceProvider::class, and App\\Providers\\EventServiceProvider::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');
```

More about `$db` see here:

#### Or use dawnings of Eloquent ORM (will be implemented completely)

[](#or-use-dawnings-of-eloquent-orm-will-be-implemented-completely)

**1.** Add model

```
