renoki-co / l1
Laravel integration for Cloudflare Workers services.
Fund package maintenance!
rennokki
Installs: 1 496
Dependents: 0
Suggesters: 0
Security: 0
Stars: 135
Watchers: 5
Forks: 25
Open Issues: 12
Requires
- doctrine/dbal: ^3.6
- illuminate/cache: ^10.23
- illuminate/database: ^10.23
- saloonphp/laravel-http-sender: ^1.2
- saloonphp/laravel-plugin: ^2.1
- saloonphp/saloon: ^2.11
Requires (Dev)
- laravel/legacy-factories: ^1.3
- mockery/mockery: ^1.5
- orchestra/testbench: ^8.3
- phpunit/phpunit: ^9.5.21
Suggests
- ext-pdo: Required to extend the PDO driver for Cloudflare D1.
- dev-master
- 0.1.0
- dev-dependabot/npm_and_yarn/tests/worker/miniflare-and-wrangler-3.20231030.4
- dev-dependabot/composer/orchestra/testbench-tw-8.18
- dev-dependabot/composer/phpunit/phpunit-tw-10.5.3
- dev-dependabot/github_actions/shivammathur/setup-php-2.28.0
- dev-dependabot/github_actions/actions/checkout-4.1.1
- dev-dependabot/npm_and_yarn/tests/worker/undici-5.26.3
- dev-dependabot/composer/saloonphp/saloon-tw-2.12
- dev-dependabot/composer/doctrine/dbal-tw-3.7
This package is auto-updated.
Last update: 2024-10-29 21:25:13 UTC
README
Extend your PHP/Laravel application with Cloudflare bindings.
This package offers support for:
π Installation
You can install the package via Composer:
composer require renoki-co/l1
π Usage
D1 with raw PDO
Though D1 is not connectable via SQL protocols, it can be used as a PDO driver via the package connector. This proxies the query and bindings to the D1's /query
endpoint in the Cloudflare API.
use RenokiCo\L1\D1\D1Pdo; use RenokiCo\L1\D1\D1PdoStatement; use RenokiCo\L1\CloudflareD1Connector; $pdo = new D1Pdo( dsn: 'sqlite::memory:', // irrelevant connector: new CloudflareD1Connector( database: 'your_database_id', token: 'your_api_token', accountId: 'your_cf_account_id', ), );
D1 with Laravel
In your config/database.php
file, add a new connection:
'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', ''), ], ], ]
Then in your .env
file, set up your Cloudflare credentials:
CLOUDFLARE_TOKEN=
CLOUDFLARE_ACCOUNT_ID=
CLOUDFLARE_D1_DATABASE_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
The d1
Β driver will proxy the PDO queries to the Cloudflare D1 API to run queries.
π Testing
Start the built-in Worker that simulates the Cloudflare API:
cd tests/worker
npm ci
npm run start
In a separate terminal, run the tests:
vendor/bin/phpunit
π€ Contributing
Please see CONTRIBUTING for details.
π Security
If you discover any security related issues, please email alex@renoki.org instead of using the issue tracker.