How to Get Raw SQL Output from the Eloquent Model in Laravel 11
In this lesson, we will see how to get raw SQL output from the eloquent model in Laravel 11, sometimes when you try to perform an action using the Laravel eloquent model and you get an error you want to print the raw SQL query to check what the exact SQL query was executed.
Get Raw SQL Output from the Eloquent Model in Laravel 11
So to get raw SQL output from the Eloquent Model in Laravel 11 use the toSql() method see the code below:
$post = Post::where('published', true)
->get();
dump($post->toSql());