Installation
Requirements
- PHP
^8.3
- Laravel
^12.0 || ^13.0 (illuminate/console, illuminate/database, illuminate/support)
- Composer
The parser core itself is pure PHP with no Laravel dependency, so it also runs in plain PHP scripts. See Without Laravel.
Install the package
composer require kwasii/laravel-sql-parser
The service provider and facade alias are auto-discovered:
// providers
Kwasii\LaravelSqlParser\LaravelSqlParserServiceProvider::class,
// aliases
'LaravelSqlParser' => Kwasii\LaravelSqlParser\Facades\LaravelSqlParser::class,
Publish the config (optional)
php artisan vendor:publish --tag="laravel-sql-parser-config"
This creates config/laravel-sql-parser.php. See Configuration for every key.
Verify it works
use Kwasii\LaravelSqlParser\Facades\LaravelSqlParser as Sql;
Route::get('/debug-sql', fn () => Sql::transpile('SELECT 1', 'mysql', 'postgres'));
Or from the CLI:
php artisan sql:transpile "SELECT IFNULL(a, 1) FROM t LIMIT 5" --from=mysql --to=sqlsrv
Production setup
For the fastest results in production:
composer dump-autoload --classmap-authoritative
Then enable OPcache and preload the parser core (about 1,100 classes). See Performance.