Member-only story

Do you know Laravel have a new function that allow us to print out sql?

Patrick Wan
1 min readAug 29, 2023

In Laravel version 10 have release function toRawSql.

// Using the new `toRawSql()` method
User::where('email', 'foo@example.com')->toRawSql();
// "SELECT * FROM users WHERE email = 'foo@example.com'"

There is some prior art before toRawSql()—various developer tools (i.e., Laravel Debugbar) give you queries, and there's a dd() method you can use as well:

// Using the dd() method
User::where('email', 'foo@example.com')->dd();
// "SELECT * FROM users WHERE email = ?"
// [
// 0 => "foo@example.com"
// ]

Read More Laravel Debugging Stories:

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Patrick Wan
Patrick Wan

Written by Patrick Wan

My name’s Patrick. I’m a Software Developer, experience in Laravel, Vue Js, React Js, Livewire, Jquery, Codegniter, NPM, GIT. I have 5 years plus experience.

No responses yet

Write a response