Portable Query Builder
Numeric JSON operations, NULLS LAST sorting, JSON increment/decrement, and JSON aggregates that compile correctly per database engine.
Cross-database query builder macros, portable schema tools, migration commands, and parallel database mirrors for Laravel 12 & 13.
When developing Laravel applications across different database engines—such as moving from CockroachDB to MatrixOne, or supporting MySQL, PostgreSQL, and SQLite simultaneously—developers encounter subtle incompatibilities:
flags->ratio > 0.8 or ordering by numbers fail or sort alphabetically ("10" before "2").NULLS LAST syntax; PostgreSQL sorts nulls first by default in descending order.group by ... with rollup vs group by rollup (...) vs union all.Laravel DB Portable bridges these differences. It compiles query macros and schema blueprints to the exact syntax required by the active database connection.
Install the package via Composer:
composer require vuthaihoc/laravel-db-portableThe package requires PHP 8.2+ and Laravel 12 or 13. The service provider is auto-discovered.
| Database | Family | Driver Package | Driver Key |
|---|---|---|---|
| PostgreSQL (14 - 17+) | pgsql | Built-in Laravel driver | pgsql |
| CockroachDB (v25 - v26+) | pgsql | vuthaihoc/cockroachdb-laravel (^2.5) | crdb |
| MySQL (8.0 - 8.4+) | mysql | Built-in Laravel driver | mysql |
| MariaDB (10.6 - 11+) | mysql | Built-in Laravel driver | mariadb |
| MatrixOne (4.2+) | mysql | vuthaihoc/laravel-matrixone (^1.2) | matrixone |
| SQLite (3.35+) | sqlite | Built-in Laravel driver | sqlite |
| XTDB (Experimental) | xtdb | vuthaihoc/laravel-xtdb2 | xtdb |
By default, when a database engine does not support a specific feature (for example, expression indexes on MariaDB/MatrixOne, or time-travel reads on SQLite), the package executes a safe fallback and logs a warning once per message:
[db-portable] asOfTime() is not supported on SQLite. Skipped.To enforce strict compatibility during automated tests or CI, enable strict mode in config/db-portable.php or dynamically:
config(['db-portable.strict' => true]);In strict mode, unsupported operations immediately throw a \RuntimeException instead of logging and falling back.
Publish the configuration file using Artisan:
php artisan vendor:publish --tag=db-portable-configThe file config/db-portable.php contains settings for strict mode, mirrors, queue connections, and model-specific overrides.