I have this query eloquent in Laravel
, I was curious to know. If there is a way to know how many records inserted or how many records ignored to the table?
DB::table('mytable')->insertOrIgnore($data)
Note: One of the manual ways can be, counting records of table before and after process. but this has performance effect, if there be any better way achieving this.
The function insertOrIgnore()
returns the affected rows.
/**
* Insert a new record into the database while ignoring errors.
*
* @param array $values
* @return int
*/
public function insertOrIgnore(array $values) {
So you can simply used the affected and compare to to what was expected to be inserted.
$affected = DB::table('mytable')->insertOrIgnore($data);
$ignored = count($data) - $affected;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments