xinningsu / laravel-raw-sql
Get raw sql from laravel query builder via toRawSql method.
Installs: 257
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/xinningsu/laravel-raw-sql
Requires
- php: ^7.0 || ^8.0
- laravel/framework: >=5.5
Requires (Dev)
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: >=6.0
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2025-10-06 14:28:37 UTC
README
Get raw sql from laravel query builder via toRawSql method.
Background
Using toSql method to output the sql of query builder, it's something with ?, not the raw sql.
use Illuminate\Support\Facades\DB; use App\Models\User; echo DB::table('user')->where('id', 1)->where('verified', 1)->toSql(); // or echo User::where('id', 1)->where('verified', 1)->toSql();
The output would be something like this with ?:
select * from `user` where `id` = ? and `verified` = ?
I exactly want the raw SQL like this:
select * from `user` where `id` = 1 and `verified` = 1
Now with this package, we can get the raw sql via toRawSql.
echo DB::table('user')->where('id', 1)->where('verified', 1)->toRawSql(); // or echo User::where('id', 1)->where('verified', 1)->toRawSql();
Will output
select * from `user` where `id` = 1 and `verified` = 1
Installation
Require this package with composer.
composer require xinningsu/laravel-raw-sql
As this package using laravel Package Discovery to discover Sulao\RawSql\ServiceProvider::class, so there's no need to do anything else, please use it directly.