PHPackages                             ntanduy/cloudflare-d1-database - 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. ntanduy/cloudflare-d1-database

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

ntanduy/cloudflare-d1-database
==============================

Easy configuration and setup for D1 Database connections in Laravel.

v0.5.0(1mo ago)215.4k—8.3%6[1 PRs](https://github.com/TanDuy03/cloudflare-d1-database/pulls)MITPHPPHP ^8.2CI passing

Since Nov 5Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/TanDuy03/cloudflare-d1-database)[ Packagist](https://packagist.org/packages/ntanduy/cloudflare-d1-database)[ Docs](https://github.com/TanDuy03/cloudflare-d1-database)[ GitHub Sponsors](https://github.com/TanDuy03)[ RSS](/packages/ntanduy-cloudflare-d1-database/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (23)Versions (20)Used By (0)

D1 - Cloudflare bindings for Laravel
====================================

[](#d1---cloudflare-bindings-for-laravel)

[![codecov](https://camo.githubusercontent.com/2b7452b7913321aee4427325964d781a97db7e7ba72ad6a12b18eb0a1a2c462c/68747470733a2f2f636f6465636f762e696f2f67682f54616e44757930332f636c6f7564666c6172652d64312d64617461626173652f67726170682f62616467652e7376673f746f6b656e3d394d534a3532375a4d58)](https://codecov.io/gh/TanDuy03/cloudflare-d1-database)[![Tests](https://github.com/TanDuy03/cloudflare-d1-database/actions/workflows/tests.yml/badge.svg)](https://github.com/TanDuy03/cloudflare-d1-database/actions/workflows/tests.yml)[![Packagist Dependency Version](https://camo.githubusercontent.com/b0b6ccb7a4cf19ebf5ff035a9f5bd0c224da866d72faf4163483470f7b2a2942/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6e74616e6475792f636c6f7564666c6172652d64312d64617461626173652f706870)](https://camo.githubusercontent.com/b0b6ccb7a4cf19ebf5ff035a9f5bd0c224da866d72faf4163483470f7b2a2942/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6e74616e6475792f636c6f7564666c6172652d64312d64617461626173652f706870)[![Latest Stable Version](https://camo.githubusercontent.com/d628514d150e0d04ac534664ba47e5de5f6ab157d94bd1372c2b9a38d4c742e4/68747470733a2f2f706f7365722e707567782e6f72672f6e74616e6475792f636c6f7564666c6172652d64312d64617461626173652f762f737461626c65)](https://packagist.org/packages/ntanduy/cloudflare-d1-database)[![Total Downloads](https://camo.githubusercontent.com/05001ba41a834f8b20846c8d371ffda237a6c7afdf6cff5c50a202b126c8059e/68747470733a2f2f706f7365722e707567782e6f72672f6e74616e6475792f636c6f7564666c6172652d64312d64617461626173652f646f776e6c6f616473)](https://packagist.org/packages/ntanduy/cloudflare-d1-database)[![Monthly Downloads](https://camo.githubusercontent.com/02987b299cb6c9466843887b4c519c5ab2c2583fcfdd531eccf618fa51e26607/68747470733a2f2f706f7365722e707567782e6f72672f6e74616e6475792f636c6f7564666c6172652d64312d64617461626173652f642f6d6f6e74686c79)](https://packagist.org/packages/ntanduy/cloudflare-d1-database)[![License](https://camo.githubusercontent.com/b40ca42b8d6f352d6887276e2dfc79099a4516ef3c1ac067bb9769352b7cbd66/68747470733a2f2f706f7365722e707567782e6f72672f6e74616e6475792f636c6f7564666c6172652d64312d64617461626173652f6c6963656e7365)](https://packagist.org/packages/ntanduy/cloudflare-d1-database)

Integrate Cloudflare bindings into your PHP/Laravel application.

🎯 Requirements
--------------

[](#-requirements)

- **PHP**: &gt;= 8.2
- **Laravel**: 10.x, 11.x, or 12.x

✨ Features
----------

[](#-features)

This package offers support for:

- [Cloudflare D1](https://developers.cloudflare.com/d1)

🚀 Installation
--------------

[](#-installation)

```
composer require ntanduy/cloudflare-d1-database
```

👏 Usage
-------

[](#-usage)

### Integrate Cloudflare D1 with Laravel

[](#integrate-cloudflare-d1-with-laravel)

Choose one of the two methods below to integrate Cloudflare D1 into your Laravel project:

### Option 1: Automatic Setup (Recommended)

[](#option-1-automatic-setup-recommended)

This method is the quickest way to get started without manually editing your system configuration files.

**Publish Configuration:** Run the following command to automatically generate the D1 configuration:

```
php artisan vendor:publish --tag="d1-config"
```

### Option 2: Manual Setup

[](#option-2-manual-setup)

If you prefer to manage the connection directly within Laravel's main configuration, add the following array to the `connections` section in your `config/database.php` file:

```
'connections' => [
    'd1' => [
        'driver' => 'd1',
        'prefix' => '',
        'database' => env('CLOUDFLARE_D1_DATABASE_ID', ''),
        'api' => 'https://api.cloudflare.com/client/v4',
        'auth' => [
            'token' => env('CLOUDFLARE_TOKEN', ''),
            'account_id' => env('CLOUDFLARE_ACCOUNT_ID', ''),
        ],
        'timeout' => env('D1_TIMEOUT', 10),
        'connect_timeout' => env('D1_CONNECT_TIMEOUT', 5),
        'retries' => env('D1_RETRIES', 2),
        'retry_delay' => env('D1_RETRY_DELAY', 100),
    ],
]
```

Next, configure your Cloudflare credentials in the `.env` file:

```
CLOUDFLARE_TOKEN=your_api_token
CLOUDFLARE_ACCOUNT_ID=your_account_id
CLOUDFLARE_D1_DATABASE_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

```

### Configuration Options

[](#configuration-options)

OptionDefaultDescription`timeout`10Request timeout in seconds`connect_timeout`5Connection timeout in seconds`retries`2Max retry attempts on 5xx/429 errors`retry_delay`100Base delay between retries (ms)For production, you can tune these via `.env`:

```
D1_TIMEOUT=10
D1_CONNECT_TIMEOUT=5
D1_RETRIES=2
D1_RETRY_DELAY=100

```

The `d1` driver will forward PDO queries to the Cloudflare D1 API to execute them.

⚠️ Limitations
--------------

[](#️-limitations)

- **No real transactions**: D1 doesn't support `BEGIN`/`COMMIT`/`ROLLBACK`. The driver simulates transaction state for Laravel compatibility, but queries are executed immediately.
- **REST API latency**: Each query is an HTTP request (~100-500ms). For low-latency needs, consider using Cloudflare Workers with native D1 bindings.

🌱 Testing
---------

[](#-testing)

Start the built-in Worker to simulate the Cloudflare API:

```
cd tests/worker
npm ci
npm run start
```

In a separate terminal, run the tests:

```
vendor/bin/pest
```

🤝 Contributing
--------------

[](#-contributing)

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

🔒 Security
----------

[](#-security)

If you discover any security related issues, please email  instead of using the issue tracker.

🎉 Credits
---------

[](#-credits)

- [TanDuy03](https://github.com/TanDuy03)
- [All Contributors](../../contributors)

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance88

Actively maintained with recent releases

Popularity34

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 99.1% 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.

###  Release Activity

Cadence

Every ~34 days

Recently: every ~8 days

Total

16

Last Release

51d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/780a6cb42e3276222c7da4602f6580dd910922d133f923a7a8f8e4d42a4b6c9c?d=identicon)[TanDuy03](/maintainers/TanDuy03)

---

Top Contributors

[![TanDuy03](https://avatars.githubusercontent.com/u/95908945?v=4)](https://github.com/TanDuy03 "TanDuy03 (114 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

cloudflared1laravellaraveldatabasecloudflared1TanDuy03

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ntanduy-cloudflare-d1-database/health.svg)

```
[![Health](https://phpackages.com/badges/ntanduy-cloudflare-d1-database/health.svg)](https://phpackages.com/packages/ntanduy-cloudflare-d1-database)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[renoki-co/l1

Laravel integration for Cloudflare Workers services.

16113.1k](/packages/renoki-co-l1)[jerome/filterable

Streamline dynamic Eloquent query filtering with seamless API request integration and advanced caching strategies.

19226.1k](/packages/jerome-filterable)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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