Laravel comes with a lot of helper functions to interact with Database efficiently . There are Eloquent which composes an ORM model, and helps to write expressive relations and queries. But some cases that’s not enough, we have to have some raw queies need to write to achieve the results. So in this article we are discussing difference between Laravel’s raw SQL functions.
This generates a raw query which means “non-sanitized” string. Laravel wrote a beautiful warning message in the docs, as it might cause security issues if don’t use it wisely.
This method is intended for simple selects.
DB::select(DB::raw('select * from customers'));
This method is very useful when running queires other than CRUD, like alter a table field or disable forieng key checks etc.
DB::statement('ALTER TABLE THIS FIELD');
This will help you to run a query that cannot be run prepared. This is not documented in Laravel docs, but we can see it declared in the code.