Hi,
I am saving multiple records. The code save multiple records but I dont understand how I can detect an error with saving in cakephp3.
The check I have in place will always return true I believe.
if (!empty($data)){
$lessons = $this->Lessons->newEntities($data, ['validate' => false]);
//saves all in 1 transaction instead of 1 by 1
$this->Lessons->connection()->transactional(function () use ( $lessons) {
foreach ($lessons as $item) {
$result=$this->Lessons->save($item, ['atomic' => false]);
if ( $result ){ //this is the check for error when saving
$this->Flash->success(__('A lesson has been saved on .'. $item->lesson_date));
$last_record_id=$result->id;
}
else{
$this->Flash->error(__('There has been an error saving a lesson. Please, try again.'));
}
}
});
}//if not empty