@@ -257,13 +257,13 @@ protected function doFirst()
257257
258258 if ($ this ->tempUseSoftDeletes ) {
259259 $ builder ->where ($ this ->table . '. ' . $ this ->deletedField , null );
260- } elseif ($ this ->useSoftDeletes && empty ($ builder ->QBGroupBy ) && $ this ->primaryKey ) {
260+ } elseif ($ this ->useSoftDeletes && ($ builder ->QBGroupBy === [] ) && $ this ->primaryKey ) {
261261 $ builder ->groupBy ($ this ->table . '. ' . $ this ->primaryKey );
262262 }
263263
264264 // Some databases, like PostgreSQL, need order
265265 // information to consistently return correct results.
266- if ($ builder ->QBGroupBy && empty ($ builder ->QBOrderBy ) && $ this ->primaryKey ) {
266+ if ($ builder ->QBGroupBy && ($ builder ->QBOrderBy === [] ) && $ this ->primaryKey ) {
267267 $ builder ->orderBy ($ this ->table . '. ' . $ this ->primaryKey , 'asc ' );
268268 }
269269
@@ -286,7 +286,7 @@ protected function doInsert(array $row)
286286
287287 // Require non-empty primaryKey when
288288 // not using auto-increment feature
289- if (! $ this ->useAutoIncrement && empty ($ row [$ this ->primaryKey ])) {
289+ if (! $ this ->useAutoIncrement && ! isset ($ row [$ this ->primaryKey ])) {
290290 throw DataException::forEmptyPrimaryKey ('insert ' );
291291 }
292292
@@ -351,7 +351,7 @@ protected function doInsertBatch(?array $set = null, ?bool $escape = null, int $
351351 foreach ($ set as $ row ) {
352352 // Require non-empty primaryKey when
353353 // not using auto-increment feature
354- if (! $ this ->useAutoIncrement && empty ($ row [$ this ->primaryKey ])) {
354+ if (! $ this ->useAutoIncrement && ! isset ($ row [$ this ->primaryKey ])) {
355355 throw DataException::forEmptyPrimaryKey ('insertBatch ' );
356356 }
357357 }
@@ -433,7 +433,7 @@ protected function doDelete($id = null, bool $purge = false)
433433 }
434434
435435 if ($ this ->useSoftDeletes && ! $ purge ) {
436- if (empty ( $ builder ->getCompiledQBWhere ()) ) {
436+ if ($ builder ->getCompiledQBWhere () === [] ) {
437437 throw new DatabaseException (
438438 'Deletes are not allowed unless they contain a "where" or "like" clause. '
439439 );
@@ -557,7 +557,7 @@ public function getIdValue($row)
557557 return $ row ->{$ this ->primaryKey };
558558 }
559559
560- if (is_array ($ row ) && ! empty ($ row [$ this ->primaryKey ])) {
560+ if (is_array ($ row ) && isset ($ row [$ this ->primaryKey ])) {
561561 return $ row [$ this ->primaryKey ];
562562 }
563563
@@ -591,7 +591,7 @@ public function chunk(int $size, Closure $userFunc)
591591
592592 $ offset += $ size ;
593593
594- if (empty ( $ rows) ) {
594+ if ($ rows === [] ) {
595595 continue ;
596596 }
597597
@@ -648,7 +648,7 @@ public function builder(?string $table = null)
648648 // We're going to force a primary key to exist
649649 // so we don't have overly convoluted code,
650650 // and future features are likely to require them.
651- if (empty ( $ this ->primaryKey ) ) {
651+ if ($ this ->primaryKey === '' ) {
652652 throw ModelException::forNoPrimaryKey (static ::class);
653653 }
654654
@@ -729,8 +729,8 @@ protected function shouldUpdate($row): bool
729729 */
730730 public function insert ($ row = null , bool $ returnID = true )
731731 {
732- if (! empty ($ this ->tempData ['data ' ])) {
733- if (empty ( $ row) ) {
732+ if (isset ($ this ->tempData ['data ' ])) {
733+ if ($ row === null ) {
734734 $ row = $ this ->tempData ['data ' ];
735735 } else {
736736 $ row = $ this ->transformDataToArray ($ row , 'insert ' );
@@ -792,8 +792,8 @@ protected function doProtectFieldsForInsert(array $row): array
792792 */
793793 public function update ($ id = null , $ row = null ): bool
794794 {
795- if (! empty ($ this ->tempData ['data ' ])) {
796- if (empty ( $ row) ) {
795+ if (isset ($ this ->tempData ['data ' ])) {
796+ if ($ row === null ) {
797797 $ row = $ this ->tempData ['data ' ];
798798 } else {
799799 $ row = $ this ->transformDataToArray ($ row , 'update ' );
@@ -910,7 +910,7 @@ public static function classToArray($data, $primaryKey = null, string $dateForma
910910 $ properties = $ data ->toRawArray ($ onlyChanged );
911911
912912 // Always grab the primary key otherwise updates will fail.
913- if (! empty ( $ properties) && ! empty ($ primaryKey ) && ! in_array ($ primaryKey , $ properties , true ) && ! empty ($ data ->{$ primaryKey })) {
913+ if ($ properties !== [] && isset ($ primaryKey ) && ! in_array ($ primaryKey , $ properties , true ) && isset ($ data ->{$ primaryKey })) {
914914 $ properties [$ primaryKey ] = $ data ->{$ primaryKey };
915915 }
916916 } else {
0 commit comments