xinningsu / laravel-raw-sql
Get raw sql from laravel query builder via toRawSql method.
v1.0
2021-01-11 06:20 UTC
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: 2024-11-06 12:16:02 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.