Sometimes you want to know the exact Laravel raw query , the exact SQL output string executed under the hood, for a given instance of the database query builder.
Let’s say you have this query:
DB::table('users')->get();
You can get the raw SQL query string that the query builder above will generate in at least two ways:
- use the toSql() function
- use the enableQueryLog() function