getConnection(); $connection->insert($sql, $values); if ($connection->getConfig('odbc') === true) { $id = $this->processInsertGetIdForOdbc($connection); } else { $id = $connection->getPdo()->lastInsertId(); } return is_numeric($id) ? (int) $id : $id; } /** * Process an "insert get ID" query for ODBC. * * @param \Illuminate\Database\Connection $connection * @return int * @throws \Exception */ protected function processInsertGetIdForOdbc(Connection $connection) { $result = $connection->selectFromWriteConnection( 'SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS int) AS insertid' ); if (! $result) { throw new Exception('Unable to retrieve lastInsertID for ODBC.'); } $row = $result[0]; return is_object($row) ? $row->insertid : $row['insertid']; } /** * Process the results of a column listing query. * * @param array $results * @return array */ public function processColumnListing($results) { return array_map(function ($result) { return ((object) $result)->name; }, $results); } }