Inserts(): This method is used for insert records into the database table. No need the “id” should be autoincremented or not in the table.

Example

DB::table('bestinterviewquestion_users')->insert(
    ['title' => 'Best Interview Questions', 'email' => ‘[email protected]’]
);

It will return true or false.

insertGetId(): This method is also used for insert records into the database table. This method is used in the case when an id field of the table is auto incrementing.

It returns the id of current inserted records.

Example

$id = DB::table('bestinterviewquestion_users')->insert(
    ['title' => 'Best Interview Questions', 'email' => ‘[email protected]’]
);

Suggest An Answer

Our Particitants

insertGetId(): This method is also used for insert records into the database table. This method is used in the case when an id field of the table is auto incrementing. It returns the id of current inserted records. Example $id = DB::table(
insertgetid()