PHPackages                             ylsideas/cockroachdb-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. ylsideas/cockroachdb-laravel

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

ylsideas/cockroachdb-laravel
============================

This is my package cockroachdb-laravel

v1.4.0(2y ago)7029.5k↓23.9%8[6 PRs](https://github.com/ylsideas/cockroachdb-laravel/pulls)MITPHPPHP ^8.2CI passing

Since Dec 14Pushed 4mo ago3 watchersCompare

[ Source](https://github.com/ylsideas/cockroachdb-laravel)[ Packagist](https://packagist.org/packages/ylsideas/cockroachdb-laravel)[ Docs](https://github.com/ylsideas/cockroachdb-laravel)[ GitHub Sponsors](https://github.com/peterfox)[ RSS](/packages/ylsideas-cockroachdb-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (14)Versions (19)Used By (0)

CockroachDB Driver for Laravel
==============================

[](#cockroachdb-driver-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d6a9b25bdb7f21eb8796592e783d68c7260e363d924c310ce8c2db352fc2c863/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f796c7369646561732f636f636b726f61636864622d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ylsideas/cockroachdb-laravel)[![PHPUnit Tests](https://github.com/ylsideas/cockroachdb-laravel/actions/workflows/run-tests.yml/badge.svg)](https://github.com/ylsideas/cockroachdb-laravel/actions/workflows/run-tests.yml)[![Check & fix styling](https://github.com/ylsideas/cockroachdb-laravel/actions/workflows/pint.yml/badge.svg)](https://github.com/ylsideas/cockroachdb-laravel/actions/workflows/pint.yml)[![Total Downloads](https://camo.githubusercontent.com/75e1f630be1e40097d19d43e662dceb4828c8070f76eed6fbf4058855de0c3d3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f796c7369646561732f636f636b726f61636864622d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ylsideas/cockroachdb-laravel)[![codecov](https://camo.githubusercontent.com/0edc646c766b4cd384eeecbbcd6640dc510e32976e3a04b6197afe40690d00a6/68747470733a2f2f636f6465636f762e696f2f6769746875622f796c7369646561732f636f636b726f61636864622d6c61726176656c2f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d47434359334b5a485851)](https://codecov.io/github/ylsideas/cockroachdb-laravel)[![Help Fund](https://camo.githubusercontent.com/ee6bbf7336f13c60720410679eed19bef599bc473a09623899fbde983fef2b79/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73706f6e736f72732f7065746572666f783f7374796c653d666c61742d737175617265)](https://github.com/sponsors/peterfox)[![License](https://camo.githubusercontent.com/7b813c46b960206acccbefa419c2884f1ec1bb73fb419b852011a11fd28d7a67/687474703a2f2f706f7365722e707567782e6f72672f796c7369646561732f636f636b726f61636864622d6c61726176656c2f6c6963656e7365)](https://packagist.org/packages/ylsideas/cockroachdb-laravel)[![PHP Version Require](https://camo.githubusercontent.com/1dcbd935b17e57e0680b924949e2e6a7154e78c81316fb7c9051aba8393290cf/687474703a2f2f706f7365722e707567782e6f72672f796c7369646561732f636f636b726f61636864622d6c61726176656c2f726571756972652f706870)](https://packagist.org/packages/ylsideas/cockroachdb-laravel)

A driver/grammar for Laravel that works with CockroachDB. While CockroachDB is compatible with Postgresql, this support is not 1 to 1 meaning you may run into issues, this driver hopes to resolve those problems as much as possible.

Laravel 9 through to Laravel 11 is supported and tested against CockroachDB 22 &amp; 23.

### Supporting Open Source

[](#supporting-open-source)

[Peter Fox](https://www.peterfox.me) here, I just want to say this project has been my hardest yet. It's been a real labour of love to make and takes up a lot of time trying to organise the test suite so that compatibility is maintained between Eloquent and CockroachDB.

I see a lot of promise in using CockroachDB's serverless offering which is what compelled me to go down this route originally. You can read [an article](https://medium.com/@SlyFireFox/laravel-tip-cockroachdbs-serverless-database-322aa7f5f7ef)I made about using their service.

If you're using this project at all then do please consider [sponsoring me](https://github.com/sponsors/peterfox)as a way of encouraging more development.

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

[](#installation)

You can install the package via composer:

```
composer require ylsideas/cockroachdb-laravel
```

You need to add the connection type to the database config:

```
'crdb' => [
    'driver' => 'crdb',
    'url' => env('DATABASE_URL'),
    'host' => env('DB_HOST', '127.0.0.1'),
    'port' => env('DB_PORT', '26257'),
    'database' => env('DB_DATABASE', 'forge'),
    'username' => env('DB_USERNAME', 'forge'),
    'password' => env('DB_PASSWORD', ''),
    'charset' => 'utf8',
    'prefix' => '',
    'prefix_indexes' => true,
    'schema' => 'public',
    'sslmode' => 'prefer',
]
```

You can also use URLs.

```
DATABASE_URL=cockroachdb://:@:/?sslmode=verify-full
```

Usage
-----

[](#usage)

To enable set `DB_CONNECTION=crdb` in your .env.

Notes
-----

[](#notes)

CockroachDB should work inline with the feature set of Postgresql, with some exceptions. You can look at the features of each CockroachDB server in the CockroachDB [Docs](https://www.cockroachlabs.com/docs/stable/sql-feature-support.html).

### Deletes with Joins

[](#deletes-with-joins)

CockroachDB does not support performing deletes using joins. If you wish to do something like this you will need to use a sub-query instead.

At current if you try to call the `delete` method of the Query builder together with a `join` then a `YlsIdeas\CockroachDb\Exceptions\FeatureNotSupportedException` exception will be thrown.

### Fulltext Search

[](#fulltext-search)

Eloquent and Postgresql support Fulltext search. CockroachDB does not support any full text search meaning the feature cannot be used when using this driver.

At current if you try to create a Fulltext index using the Schema builder or try to use the `whereFulltext`method of the Query builder a `YlsIdeas\CockroachDb\Exceptions\FeatureNotSupportedException` exception will be thrown.

### Serverless Support

[](#serverless-support)

Cockroach Serverless requires you to provide a cluster with connection. Laravel doesn't provide this out of the box, so, it's being implemented as an extra `cluster` parameter in the database config. Just pass the cluster identification from CockroachDB Serverless.

### Schema Dumps

[](#schema-dumps)

You may use schema dumps. I'm not 100% sure the functionality is correct in line with other drivers. Please raise an issue if it isn't working as expect for you.

```
'crdb' => [
    'driver' => 'crdb',
    'url' => env('DATABASE_URL'),
    'host' => env('DB_HOST', '127.0.0.1'),
    'port' => env('DB_PORT', '26257'),
    'database' => env('DB_DATABASE', 'forge'),
    'username' => env('DB_USERNAME', 'forge'),
    'password' => env('DB_PASSWORD', ''),
    'charset' => 'utf8',
    'prefix' => '',
    'prefix_indexes' => true,
    'schema' => 'public',
    'sslmode' => 'prefer',
    'cluster' => env('COCKROACHDB_CLUSTER', ''),
]
```

You may also use a URL in the following format.

```
DATABASE_URL=cockroachdb://:@:/?sslmode=verify-full&cluster=
```

Testing
-------

[](#testing)

The tests try to closely follow the same functionality of the grammar provided by Laravel by lifting the tests straight from laravel/framework. This does provide some complications. Namely, cockroachdb is designed to be distributed so primary keys do not occur in sequence.

Tests should also try to be compatible with not just the latest version of Laravel but across Laravel 8, 9 and 10, this requires some tests to be skipped.

You can run up a local cockroachDB test instance using Docker compose.

```
docker-composer up -d
```

If you need to you may run the docker compose file with different cockroachdb versions

```
VERSION=v23.1.13 docker-compose up -d
```

Then run the following PHP script to create a test database and user

```
php ./database.php
```

Afterwards you can run the test suite.

```
composer test
```

To clean up, you only need stop docker composer.

```
docker-composer down
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Peter Fox](https://github.com/peterfox)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance52

Moderate activity, may be stable

Popularity41

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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.

###  Release Activity

Cadence

Every ~103 days

Recently: every ~133 days

Total

9

Last Release

785d ago

Major Versions

v0.1.0 → v1.0.02022-02-12

PHP version history (3 changes)v0.1.0PHP ^8.0

v1.3.0PHP ^8.1

v1.4.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/0b739c85248a287e7318fd7098806a90c5b8aa7e91d99e493628597eee6520e9?d=identicon)[YlsIdeas](/maintainers/YlsIdeas)

---

Top Contributors

[![peterfox](https://avatars.githubusercontent.com/u/1716506?v=4)](https://github.com/peterfox "peterfox (51 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (32 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (22 commits)")[![tryvin](https://avatars.githubusercontent.com/u/3874705?v=4)](https://github.com/tryvin "tryvin (2 commits)")[![wsamoht](https://avatars.githubusercontent.com/u/5725966?v=4)](https://github.com/wsamoht "wsamoht (1 commits)")

---

Tags

cockroachdbdatabasehacktoberfestlaravelphplaravelylsideascockroachdbcockroachdb-laravel

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/ylsideas-cockroachdb-laravel/health.svg)

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

###  Alternatives

[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[spatie/laravel-model-flags

Add flags to Eloquent models

4301.1M1](/packages/spatie-laravel-model-flags)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[spatie/laravel-sql-commenter

Add comments to SQL queries made by Laravel

1931.4M1](/packages/spatie-laravel-sql-commenter)[spatie/laravel-deleted-models

Automatically copy deleted records to a separate table

409109.8k4](/packages/spatie-laravel-deleted-models)[wnx/laravel-backup-restore

A package to restore database backups made with spatie/laravel-backup.

203330.1k2](/packages/wnx-laravel-backup-restore)

PHPackages © 2026

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