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 users
We 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

});