To get the sql query, we can use enableQueryLog
static method to print query.
We can use:
DB::enableQueryLog(); // Enable query log // Your Eloquent query dd(DB::getQueryLog()); // Show results of log
Or
We can use toSql()
to print the sql query.
DB::table('products')->toSql();
return
select * from products
That’s it!. Please share your thoughts or suggestions in the comments below.