1. Dump and Die dd() function
For example:$p = DB::table('products_data')->get();
dd($p);
or
Product::all()->dd();
The above queries will dump and die the SQL query results.
2. dump() function
Category::all()->dump();
3. toSql() method
we can get SQL raw query very easily without executing it.
For Example:
$q = DB::table('orders')->where('status', 'active');
$sql = $q->toSql();
dd($q);
This will result in an SQL query in a string form.
4. DB::raw() for Complex Queries
Conclusion
These SQL debugging techniques help you save a lot of time in fixing the SQL query issues and
pinpointing the exact issue.Also, these will make sure all queries are executed and generated properly without issue.