How Do I Get the Query Builder to Output Its Raw SQL Query as a String?

Technology CommunityCategory: LaravelHow Do I Get the Query Builder to Output Its Raw SQL Query as a String?
VietMX Staff asked 3 years ago
Problem

Given the following code:

DB::table('users')->get();

I want to get the raw SQL query string that the database query builder above will generate. How do I do this?

To output to the screen the last queries ran you can use:

DB::enableQueryLog();
dd(DB::getQueryLog());