How can I check if the query builder has inserted my data successfully?
$result = $this->database->table('user')->insert([
'uuid' => $uuid,
'name' => $name,
'email' => $email,
'created_on' => $createdOn
]);
print_r($result); // 1
But if I provide an empty array:
$result = $this->database->table('user')->insert([]);
print_r($result); // 1
I also get the same result.
So what is the best way to know if a data is inserted?
You can use insertGetId
method and then check the inserted id
exists:
$id = $this->database->table('user')->insertGetId($query);
if(empty($id){
Log::error('Failed to insert row into database.');
}