ort-interactive-gmbh/laravel-couchbase
Brings Couchbase into Laravel: an Eloquent-compatible model and query builder for buckets and collections, plus cache and session drivers. Configure connections like any Laravel database and query documents with familiar fluent syntax, including Couchbase 7 scopes and collections.
Before writing a line of application code, confirm the biggest constraint: this package (last release Feb 2018) targets the Couchbase PHP SDK 2.x (ext-couchbase with the Couchbase\Cluster/CouchbaseBucket style API), not the SDK 3.x that ships today. Run php -m | grep -i couchbase and check the extension version; on PHP 8.x you will almost certainly need a PHP 7.1/7.2 container or a fork. Treat this as a "pin the runtime first, evaluate second" package.
Minimal setup:
composer require ort-interactive-gmbh/laravel-couchbase.config/database.php — check the README for exact keys, but it is shaped like:'couchbase' => [
'driver' => 'couchbase',
'host' => env('CB_HOST', '127.0.0.1'),
'port' => env('CB_PORT', 8091),
'bucket' => env('CB_BUCKET', 'default'),
'user' => env('CB_USER'),
'password' => env('CB_PASSWORD'),
],
http://localhost:8091), give it a RAM quota, and create at least a primary index if you intend to query by anything other than document key: CREATE PRIMARY INDEX ON \bucket` USING GSI;`.protected $connection = 'couchbase';, public $incrementing = false;, protected $keyType = 'string';.First use case: a key-addressed, read-heavy collection — user profiles, session/preference documents, product catalog snapshots — where you look things up by ID or a single indexed field. Do not start by porting a relational schema.
Design keys deliberately. Couchbase is fastest when you fetch by key. Use find($id) with composite, human-readable keys (user::<uuid>, order::2024::<ulid>) generated in a creating model event or a repository factory. This lets you bypass indexes for the hottest paths.
Keep where clauses narrow and indexed. User::where('email', $email)->first() works, but only scales if a GSI index exists on email. Every new query shape in the app should come with a matching CREATE INDEX in your deployment scripts.
Denormalize instead of relating. Eloquent relationships against a document store are unreliable here. Embed related data in the document, or store a reference ID and load it explicitly through a repository. This also keeps reads to a single key lookup.
Wrap models in repositories. Put Couchbase access behind UserRepository, CatalogRepository, etc. The package's query builder has gaps versus core Eloquent; the repository boundary lets you swap in raw N1QL, the official SDK, or a different backend without touching controllers.
Use raw/N1QL as the escape hatch. For aggregations, GROUP BY, joins across document types, or anything the builder doesn't cover, drop to a raw query through the connection rather than fighting the builder. Keep these parameterized ($1, $2) to avoid injection and to reuse the query plan cache.
Treat indexes and design documents as code. There are no meaningful migrations. Keep a database/couchbase/ directory of N1QL scripts (CREATE INDEX, CREATE PRIMARY INDEX, view definitions) and run them from an artisan command or deploy step. This is your schema.
Test against a real bucket. Use the couchbase Docker image, flush the bucket in setUp, and run integration tests against it. Mocking the SDK hides index and consistency behavior that will bite you in production.
Watch connection lifecycle in workers. Long-running queue workers and Octane-style runtimes can outlive an SDK connection. Create connections per job or add a health check/reconnect in your base repository.
Couchbase\Cluster, bucket objects) differs from today's SDK. If you cannot pin PHP 7.x, budget for a fork or a thin custom repository over the official SDK.$incrementing = false and $keyType = 'string', and generate keys yourself. insertGetId() will not do what you expect.whereHas, some where* variants, orWhere grouping, and orderBy on unindexed fields. Read the builder source before assuming a method exists.where on a large bucket without a GSI will full-scan and may blow the request timeout. Reproduce in the Web Console's Query tab or cbq CLI and check the execution plan.request_plus/at_plus scan consistency at the cost of latency; don't set it globally.DB::connection('couchbase')->enableQueryLog() if the connection logs, otherwise lean on the Couchbase UI's completed-requests and query monitors. Catch CouchbaseException subclasses and translate them into domain errors rather than leaking SDK exceptions.How can I help you explore Laravel packages today?