function is_duplicate_key_exception(\Laravel\Database\Exception $e) { Log::debug("(\$e={$e})"); $duplicate = false; $entry = $key = null; $inner = $e->getInner(); $info = $inner->errorInfo; // Check if mysql error is for a duplicate key if (in_array($info[1], array(1062, 1022, 1558))) { $duplicate = true; preg_match("/'(.*)'.*'(.*)'/", $info[2], $matches); $entry = $matches[1]; $key = $matches[2]; } $ret = array($duplicate, $entry, $key, 'is_duplcate_key' => $duplicate, 'duplicate_entry' => $entry, 'for_key' => $key); Log::debug("Returning duplicate key details: " . json_encode($ret)); return $ret; }