$row) { $exists = $this->settingExits($row['section'], $row['item_key']); if ($exists) unset($rows[$key]); } if (count($rows) == 0) return; $this->table('kg_setting')->insert($rows)->save(); } protected function settingExits($section, $itemKey) { $row = $this->getQueryBuilder() ->select('*') ->from('kg_setting') ->where(['section' => $section, 'item_key' => $itemKey]) ->execute()->fetch(); return $row ? true : false; } }