@@ -1032,6 +1032,9 @@ protected function decrementEach(array $columns, array $extra = [])
10321032 */
10331033 protected function insertBuilder (array $ values , $ ignore = false )
10341034 {
1035+ $ createdAT = 'created_at ' ;
1036+ $ updatedAT = 'updated_at ' ;
1037+
10351038 // Since every insert gets treated like a batch insert, we will make sure the
10361039 // bindings are structured in a way that is convenient when building these
10371040 // inserts statements by verifying these elements are actually an array.
@@ -1040,12 +1043,21 @@ protected function insertBuilder(array $values, $ignore = false)
10401043 }
10411044
10421045 // check if timestamps is available in table
1043- // if yes then add time stamdps to columns
1046+ // if yes then add time stamps to columns
10441047 // with this helper, developers dont need to worry adding them
10451048 $ stampData = $ this ->timeStampData ();
10461049
10471050 if (! is_array (reset ($ values ))) {
1048- $ values = [array_merge ($ values , $ stampData )];
1051+
1052+ if (!isset ($ values [$ createdAT ]) && $ this ->isTimeStampsReady ){
1053+ $ values [$ createdAT ] = $ stampData [$ createdAT ];
1054+ }
1055+
1056+ if (!isset ($ values [$ updatedAT ]) && $ this ->isTimeStampsReady ){
1057+ $ values [$ updatedAT ] = $ stampData [$ updatedAT ];
1058+ }
1059+
1060+ $ values = [$ values ];
10491061 }
10501062
10511063 // Here, we will sort the insert keys for every record so that each insert is
@@ -1055,7 +1067,15 @@ protected function insertBuilder(array $values, $ignore = false)
10551067 foreach ($ values as $ key => $ value ) {
10561068 ksort ($ value );
10571069
1058- $ values [$ key ] = array_merge ($ values , $ stampData );
1070+ if (!isset ($ value [$ createdAT ]) && $ this ->isTimeStampsReady ){
1071+ $ value [$ createdAT ] = $ stampData [$ createdAT ];
1072+ }
1073+
1074+ if (!isset ($ value [$ updatedAT ]) && $ this ->isTimeStampsReady ){
1075+ $ value [$ updatedAT ] = $ stampData [$ updatedAT ];
1076+ }
1077+
1078+ $ values [$ key ] = $ value ;
10591079 }
10601080 }
10611081
@@ -1276,11 +1296,11 @@ protected function isTimeStampsReady()
12761296
12771297 // get results data
12781298 $ result = $ stmt ->fetchAll (PDO ::FETCH_COLUMN );
1279-
1280- if ( is_array ( $ result ) && count ( $ result ) === 2 ){
1281- return true ;
1282- }
1283- return false ;
1299+
1300+ // if columns exists in the table
1301+ $ this -> isTimeStampsReady = is_array ( $ result ) && count ( $ result ) === 2 ;
1302+
1303+ return $ this -> isTimeStampsReady ;
12841304 } catch (\PDOException $ th ) {
12851305 return false ;
12861306 }
@@ -1334,6 +1354,7 @@ protected function fetchAll(int $mode = PDO::FETCH_ASSOC)
13341354 */
13351355 protected function close ($ table = true )
13361356 {
1357+ $ this ->isTimeStampsReady = false ;
13371358 $ this ->bindings = [
13381359 'select ' => [],
13391360 'from ' => [],
0 commit comments