Skip to content

Laravel

darkterminal edited this page Nov 11, 2026 · 1 revision

Laravel Integration

Works out of the box with Laravel 12 — no manual provider registration.

Install

composer require darkterminal/turso-client-http

Laravel auto-discovers Darkterminal\TursoHttp\Laravel\TursoServiceProvider from the package manifest.

Configuration

.env:

DB_URL=libsql://<db>-<org>.turso.io
DB_TOKEN=<your-token>
# Local alternatives are also honored: TURSO_URL / TURSO_TOKEN

Optional — publish the config to see defaults or override:

php artisan vendor:publish --provider="Darkterminal\TursoHttp\Laravel\TursoServiceProvider" --tag=turso-http-config

config/turso-http.php:

return [
    'url' => env('DB_URL', env('TURSO_URL', 'http://127.0.0.1:8081')),
    'token' => env('DB_TOKEN', env('TURSO_TOKEN', '')),
    'options' => [],   // optional closures, e.g. before_hook / after_hook
];

Using the facade

use Darkterminal\TursoHttp\Laravel\Turso;

$version = Turso::version();

Turso::execute('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)');
Turso::execute('INSERT INTO users (name) VALUES (?)', ['Ada']);

$rows = Turso::query('SELECT * FROM users')->fetchArray(
    \Darkterminal\TursoHttp\LibSQL::LIBSQL_ASSOC
);

$tx = Turso::transaction('deferred');
$tx->execute('INSERT INTO users (name) VALUES (?)', ['Grace']);
$tx->commit();

Resolution details:

  • turso is a shared singleton — Turso::…, the service container (app('turso')), and LibSQL::class (autowired) all resolve to the same Darkterminal\TursoHttp\LibSQL instance.
  • The client is constructed from config('turso-http').

Verified end to end

docker/laravel-proof/ builds a fresh Laravel 12 application, installs this package via a path repository, and asserts (verbatim from the harness):

PROOF-LARAVEL: {"ok":5,"fail":0,"all_ok":true,"checks":{"service_provider_registered":true,"facade_resolves":true,"version_non_empty":true,"facade_round_trip":true,"transaction_committed":true}}

This harness is green on PHP 8.3, 8.4 and 8.5:

docker/laravel-proof/proof.sh          # 8.3 8.4 8.5
docker/laravel-proof/proof.sh 8.4      # single version

Doctrine/outside Laravel

Use the plain client: Basic Usage. A Doctrine DBAL driver is a separate package (turso-doctrine-dbal), as is the native-extension Laravel driver (turso-driver-laravel) — this package is the HTTP client either can stand in for.

Clone this wiki locally