Display a Laravel 5.2 eloquent query
I no longer write new content at tenghamn.com, you can find my new web related content at GoPHP.io and my personal blog posts at Ma.rkus.io.
My favorite domain registrar is NameSilo and if you use the affiliate link here it helps me earn some money from my writing: https://www.namesilo.com/pricing.php?rid=ee81e92mn, thanks! If you are new to NameSilo you can use my coupon, MARKUSTENGHAMN to save $1.00.
This post has been migrated and imported into different systems over the years, I have not had a chance to format this post manually so it may be hard to read but I have left it here as a reference.
Sometimes when working with Laravel it can be nice to see the actual query that you are generating, especially if you are dealing with really large queries. It surprised me how easy this is to do in Laravel as explained in this post https://scotch.io/tutorials/debugging-queries-in-laravel.
Basically all we need to do is replace ‘->get()’ at the end of our statement with ‘->toSql()’ which will print our statement.<br></br>