The former creates an in-memory Expression object which you can use in your queries whereas the latter immediately executes any statement/expression you pass along.
Dec 19, 2021
7
Level 39
DB::raw vs DB::statement
I just noticed that DB::raw does not return any error, DB::statement (and other cdes) does.
There should be an explanation in the code, but I did not find any note about this in the documentation, neither in the web. Does sb have more information?
Level 102
@sr57 not every single detail is mentioned in the docs. So often looking at the source is the way to go
https://github.com/laravel/framework/blob/8.x/src/Illuminate/Database/Connection.php#L890
Vs
https://github.com/laravel/framework/blob/8.x/src/Illuminate/Database/Connection.php#L492
And what code would you expect to give an error? Can you show example?
2 likes
Please or to participate in this conversation.