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.

The actual output you want is
 SELECT * FROM users
We need to use toSql() in the QueryBuilder instance

or use QueryLog like this.
For Laravel versions 5.2 and above use DBListen

DB::listen(function ($query) {

// $query->sql

// $query->bindings

// $query->time