The difference between Laravel DB :: insert () and DB :: table () & # 8594; insert ()

I tried to figure out which one to use, and if I should use both.

Looked at the Laravel docs, and they are both there. From what I can make of this, it DB::insert()provides a more "individual" request than DB::table()->insert()it does.

Can anyone clarify exactly what the difference is in how and when to use which?

+4
source share
1 answer
  • DB::insert()for raw sql queries . Example:

    DB::insert('insert into users (id, name) values (?, ?)', [1, 'Dayle']);

  • DB::table()->insert()for query builder . Example:

    DB::table('users')->insert( ['email' => 'john@example.com', 'votes' => 0] );

sql-, ,

+10

Source: https://habr.com/ru/post/1652303/


All Articles