Outputting Eloquent query unparameterized in Laravel

1 · Amit Merchant · July 24, 2021, 7:02 a.m.
One of the many benefits of using Laravel as a framework is the immense customizability it comes with. So, you can use this to overcome some of the limitations. For instance, currently, if you want to output an Eloquent query in its SQL form, you can invoke the toSql() method onto it like so. $books = Book::where('author', 'Ruskin Bond')->toSql(); dd($books); // select * from `books` where `author` = ? As you can tell, the toSql() would output the query but if you notice it doesn’t really outp...