From b5360918306b0e74a4fb05cadfdc9dfec893abb7 Mon Sep 17 00:00:00 2001 From: Watheq Alshowaiter Date: Sun, 21 Jul 2024 02:45:36 +0300 Subject: [PATCH] fix: convert "NULL" values to null for mariadb in newer versions --- src/RequiredFields.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/RequiredFields.php b/src/RequiredFields.php index b399ab2..4d30aea 100644 --- a/src/RequiredFields.php +++ b/src/RequiredFields.php @@ -28,16 +28,16 @@ public static function getRequiredFields( ); } - if (DB::connection()->getDriverName() == 'mariadb') { // mariadb has special case for nullables - dump( - Schema::getColumns((new self())->getTable()) // todo remove it later - ); - return self::getRequiredFieldsForOlderVersions( - $withNullables, - $withDefaults, - $withPrimaryKey - ); - } + // if (DB::connection()->getDriverName() == 'mariadb') { // mariadb has special case for nullables + // // dump( + // // Schema::getColumns((new self())->getTable()) // todo remove it later + // // ); + // return self::getRequiredFieldsForOlderVersions( + // $withNullables, + // $withDefaults, + // $withPrimaryKey + // ); + // } $primaryIndex = collect(Schema::getIndexes((new self())->getTable())) ->filter(function ($index) { @@ -48,6 +48,13 @@ public static function getRequiredFields( ->toArray(); return collect(Schema::getColumns((new self())->getTable())) + ->map(function ($column) { // specific to mariadb + if ($column['default'] == 'NULL') { + $column['default'] = null; + } + + return $column; + }) ->reject(function ($column) use ($primaryIndex, $withNullables, $withDefaults) { return $column['nullable'] && !$withNullables ||