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, 2020 in Laravel by kartik
• 37,520 points
4,220 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, 2020 by Niroj
• 82,840 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, 2020 in Laravel by Niroj
• 82,840 points
4,063 views
+1 vote
4 answers

How to access images inside public folder in laravel?

If you are inside a blade template {{ ...READ MORE

answered Dec 14, 2020 in Laravel by Rajiv
• 8,870 points
131,777 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, 2020 in Laravel by Niroj
• 82,840 points
2,339 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, 2020 in Laravel by Niroj
• 82,840 points
7,803 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, 2020 in Laravel by Niroj
• 82,840 points
23,012 views
0 votes
1 answer

What is redirection in Laravel?

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

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
2,995 views
0 votes
1 answer

How to install Laravel via composer?

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

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,918 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, 2020 in Laravel by Niroj
• 82,840 points
44,691 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, 2020 in Laravel by Niroj
• 82,840 points
4,982 views
0 votes
1 answer

How to use mail() in laravel?

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

answered Mar 24, 2020 in Laravel by Niroj
• 82,840 points
940 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP