Getting raw sql query output from query builder
In Laravel the query builder generates the query but if you need the raw query as a string you add some lines to the code. For example, the query given below is the query genereated by query builder.
DB::table('users')->get();The actual output you want is
SELECT * FROM usersWe need to use toSql() in the QueryBuilder instance
DB::table('users')->toSql()or use QueryLog like this.
DB::getQueryLog()For Laravel versions 5.2 and above use DBListen
DB::listen(function ($query) {// $query->sql
// $query->bindings
// $query->time
});
Comments
0 comments
Please Sign in or Create an account to Post Comments