Why to use DB::raw inside DB::select in Laravel?

0 votes

Is it mandatory to use the function DB::raw when you are running a query and you are not using the fluent query builder in Laravel?

e.g.

$result = DB::select("SELECT * FROM users");

$result2 = DB::select(DB::raw("SELECT * FROM users"));

I get the same result in both cases. So why is it necessary to use DB::raw?

Oct 28 in Laravel by kartik
• 35,300 points
26 views

1 answer to this question.

0 votes

Hello @kartik,

DB::raw() is used to make arbitrary SQL commands which aren't parsed any further by the query builder. They therefore can create a vector for attack via SQL injection.

Hope it helps!!

answered Oct 28 by Niroj
• 76,540 points

Related Questions In Laravel

0 votes
1 answer

How to make a constant and use globally in laravel?

Hii, You can create a constants.php page in config folder ...READ MORE

answered Mar 24 in Laravel by Niroj
• 76,540 points
135 views
+1 vote
2 answers

How to access images inside public folder in laravel?

You simply need to use the asset helper function ...READ MORE

answered Aug 27 in Laravel by Dsouza
• 150 points
12,875 views
0 votes
1 answer

How to use multiple databases in Laravel?

Hello @kartik, Laravel has inbuilt support for multiple ...READ MORE

answered Jul 30 in Laravel by Niroj
• 76,540 points
130 views
0 votes
1 answer

How to use API Routes in Laravel?

Hello @kartik, You call it by http://localhost:8080/api/test ...READ MORE

answered Aug 10 in Laravel by Niroj
• 76,540 points
735 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 76,540 points
3,435 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18 in Laravel by Niroj
• 76,540 points
411 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23 in Laravel by Niroj
• 76,540 points
281 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23 in Laravel by Niroj
• 76,540 points
4,140 views
0 votes
1 answer

How to use Stored Procedures in Laravel?

Hey, To create a Stored Procedure you can ...READ MORE

answered Mar 24 in Laravel by Niroj
• 76,540 points
1,275 views
0 votes
1 answer

How to use mail() in laravel?

Hello, Laravel provides a powerful and clean API ...READ MORE

answered Mar 24 in Laravel by Niroj
• 76,540 points
107 views