PHPackages                             lroman242/laravel-cassandra - 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. lroman242/laravel-cassandra

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

lroman242/laravel-cassandra
===========================

A Cassandra based Eloquent model and Query builder for Laravel (Casloquent)

23251PHP

Since Mar 23Pushed 6y ago1 watchersCompare

[ Source](https://github.com/lroman242/laravel-cassandra)[ Packagist](https://packagist.org/packages/lroman242/laravel-cassandra)[ RSS](/packages/lroman242-laravel-cassandra/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)DependenciesVersions (6)Used By (0)

Laravel Cassandra
=================

[](#laravel-cassandra)

A Cassandra based Eloquent model and Query builder for Laravel (Casloquent)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/0e07a9eb91c89da0b902b98edb2f2ebbe819d02a67faf18e36bbdf19ea1b4e2d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c726f6d616e3234322f6c61726176656c2d63617373616e6472612f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/lroman242/laravel-cassandra/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/dd91166a20fbd62bd6ad681b18c3744213f0d2aef860f379ac35add536961c13/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c726f6d616e3234322f6c61726176656c2d63617373616e6472612f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/lroman242/laravel-cassandra/?branch=master)[![Build Status](https://camo.githubusercontent.com/d5fb0c4d889109d89a06c0905c9079f83405e61004d88e33eb119ed381f18cae/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c726f6d616e3234322f6c61726176656c2d63617373616e6472612f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/lroman242/laravel-cassandra/build-status/master)

**Real test coverage is much lower**

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

[](#installation)

### Laravel version Compatibility

[](#laravel-version-compatibility)

LaravelPackage5.4.x - 5.5.xv0.1.2Make sure you have the Cassandra PHP driver installed (version 1.2+). You can find more information at .

Installation using composer:

```
composer require lroman242/laravel-cassandra

```

#### Laravel

[](#laravel)

And add the service provider in `config/app.php`:

```
lroman242\LaravelCassandra\CassandraServiceProvider::class,
```

The service provider will register a cassandra database extension with the original database manager. There is no need to register additional facades or objects. When using cassandra connections, Laravel will automatically provide you with the corresponding cassandra objects.

For usage outside Laravel, check out the [Capsule manager](https://github.com/illuminate/database/blob/master/README.md) and add:

```
$capsule->getDatabaseManager()->extend('cassandra', function($config)
{
    return new lroman242\LaravelCassandra\Connection($config);
});
```

#### Lumen

[](#lumen)

Add next lines to your `bootstrap.php`

```
    $app->configure('database');
```

```
    $app->register(lroman242\LaravelCassandra\CassandraServiceProvider::class);
```

Configuration
-------------

[](#configuration)

Change your default database connection name in `config/database.php`:

```
'default' => env('DB_CONNECTION', 'cassandra'),
```

And add a new cassandra connection:

```
'cassandra' => [
    'driver'          => 'cassandra',
    'host'            => env('DB_HOST', 'localhost'),
    'port'            => env('DB_PORT', 9042),
    'keyspace'        => env('DB_DATABASE'),
    'username'        => env('DB_USERNAME'),
    'password'        => env('DB_PASSWORD'),
    'page_size'       => env('DB_PAGE_SIZE', 5000),
    'consistency'     => Cassandra::CONSISTENCY_LOCAL_ONE,
    'timeout'         => null,
    'connect_timeout' => 5.0,
    'request_timeout' => 12.0,
],
```

You can connect to multiple servers with the following configuration:

```
'cassandra' => [
    'driver'          => 'cassandra',
    'host'            => ['192.168.0.1', '192.168.0.2'], //or '192.168.0.1,192.168.0.2'
    'port'            => env('DB_PORT', 9042),
    'keyspace'        => env('DB_DATABASE'),
    'username'        => env('DB_USERNAME'),
    'password'        => env('DB_PASSWORD'),
    'page_size'       => env('DB_PAGE_SIZE', 5000),
    'consistency'     => Cassandra::CONSISTENCY_LOCAL_ONE,
    'timeout'         => null,
    'connect_timeout' => 5.0,
    'request_timeout' => 12.0,
],
```

Note: you can enter all of your nodes in .env like :

```
# .env
DB_HOST=192.168.0.1,192.168.0.2,192.168.0.3

```

Note: list of available consistency levels (php constants):

```
Cassandra::CONSISTENCY_ANY
Cassandra::CONSISTENCY_ONE
Cassandra::CONSISTENCY_TWO
Cassandra::CONSISTENCY_THREE
Cassandra::CONSISTENCY_QUORUM
Cassandra::CONSISTENCY_ALL
Cassandra::CONSISTENCY_SERIAL
Cassandra::CONSISTENCY_QUORUM
Cassandra::CONSISTENCY_LOCAL_QUORUM
Cassandra::CONSISTENCY_EACH_QUORUM
Cassandra::CONSISTENCY_LOCAL_SERIAL
Cassandra::CONSISTENCY_LOCAL_ONE

```

Note: you can set specific consistency level according to the query using options

Eloquent
--------

[](#eloquent)

#### Model Usage

[](#model-usage)

Supported most of eloquent query build features, events, fields access.

```
    $users = User::all();

    $user = User::where('email', 'tester@test.com')->first();

    $user = User::find(new \Cassandra\Uuid("7e4c27e2-1991-11e8-accf-0ed5f89f718b"))
```

Relations - NOT SUPPORTED

#### Attributes casting

[](#attributes-casting)

There is ability to use UUID as model primary key

```
class Item
{
    ...

    protected $keyType = 'uuid';

    public $incrementing = true; // will automatically cast your primary key to keyType

    // OR

    protected $keyType = 'uuid';

    public $incrementing = false;

    protected $casts = [
        'id' => 'uuid',
    ];
    ...
}

```

Query Builder
-------------

[](#query-builder)

The database driver plugs right into the original query builder. When using cassandra connections, you will be able to build fluent queries to perform database operations.

```
$users = DB::table('users')->get();

$user = DB::table('users')->where('name', 'John')->first();
```

If you did not change your default database connection, you will need to specify it when querying.

```
$user = DB::connection('cassandra')->table('users')->get();
```

Default use of `get` method of query builder will call chunked fetch from database. Chunk size can be configured on config file (` 'page_size' => env('DB_PAGE_SIZE', 5000)`) or with additional query builder`s method `setPageSize`.

```
$comments = Comments::setPageSize(500)->get(); // will return all comments, not 500
```

**WARNING**: Not recomended to use `get` if there are a lot of data in table. Use `getPage` instead.

Get single page of resuts

```
$comments = Comments::setPageSize(500)->getPage(); // will return collection with 500 results
```

There is an ability to set next page token what allows to get next chunk of results

```
$comments = Comments::setPaginationStateToken($token)->getPage();
```

Get next page:

```
$comments = $comments->nextPage();
```

Get next page token:

```
$comments = $comments->getNextPageToken();
```

Append collection with next page`s result:

```
$comments->appendNextPage();
```

Check if it is last page:

```
$comments->isLastPage();
```

Get raw cassandra response for current page (\\Cassandra\\Rows):

```
$rows = $commants->getRows();
```

Read more about the query builder on

Examples
--------

[](#examples)

- store users data to csv

```
$users = User::setPageSize(1000)->getPage();
while(!$users->isLastPage()) {
    foreach($users as $user) {
        // here you can write a lines to csv file
    }

    $users = $users->nextPage();
}
```

- Simple api to make `Load more` as paggination on page

```
public function getComments(Request $request) {
    ...

    $comments = Comment::setPageSize(50)
        ->setPaginationStateToken($request->get('nextPageToken', null)
        ->getPage();

    ...

    return response()->json([
        ...
        'comments' => $comments,
        'nextPageToken' => !$comments->isLastPage() ? $comments->getNextPageToken() : null,
        ...
    ]);
}
```

- If you use cassandra materialized views you can easily use it with eloquent models

```
$users = User::from('users_by_country_view')->where('country', 'USA')->get();
```

TODO:
-----

[](#todo)

- full support of composite primary key
- full test coverage
- fix diff between \\Cassandra\\Date with Carbon
- add schema queries support
- add ability to use async queries

Docker:
-------

[](#docker)

There is docker-compose setup stored in package root. It can be used for local development and test running. Works well with PHPStorm testing tools + coverage.

Run command below inside of the "main" container to run tests and generate coverage file:

```
vendor/bin/phpunit --coverage-clover clover.xml
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c82c65510c1b840fe933ff94238e70128fa77c3cf3d32f922cf30392d99c10ec?d=identicon)[lroman242](/maintainers/lroman242)

---

Top Contributors

[![lroman242](https://avatars.githubusercontent.com/u/11349698?v=4)](https://github.com/lroman242 "lroman242 (57 commits)")[![Fuitad](https://avatars.githubusercontent.com/u/263288?v=4)](https://github.com/Fuitad "Fuitad (1 commits)")

---

Tags

casloquentcassandracassandra-cqllaravellaravel-cassandralumen

### Embed Badge

![Health badge](/badges/lroman242-laravel-cassandra/health.svg)

```
[![Health](https://phpackages.com/badges/lroman242-laravel-cassandra/health.svg)](https://phpackages.com/packages/lroman242-laravel-cassandra)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
