Answer the question
In order to leave comments, you need to log in
insert..." and "DB::insert('insert into admins (name, email) values...") in Laravel 5?" />
What is the difference between "DB::table('users')->insert..." and "DB::insert('insert into admins (name, email) values...") in Laravel 5?
Here is from the documentation (standard examples)
DB::table('users')->insert([
'name' => str_random(10),
'email' => str_random(10).'@gmail.com',
'password' => bcrypt('secret'),
]);
DB::insert('insert into users (id, name) values (?, ?)', [1, 'Dayle'])
What is the difference?
Answer the question
In order to leave comments, you need to log in
In the first case, laravel will collect the request itself, in the second case, you write the request with pens.
Practical meaning: when writing queries with your hands, you can implement your own complex sql query logic.
Dmitry Entelis answered absolutely right, but I would add. Another difference is that if you want to change the DBMS, then you do not have to manually change all your queries, and Laravel will independently assemble the query for the new one. Those. it's a compatibility issue.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question