Skip to content

Commit

Permalink
fix: convert "NULL" values to null for mariadb in newer versions
Browse files Browse the repository at this point in the history
  • Loading branch information
WatheqAlshowaiter committed Jul 20, 2024
1 parent 5b632d5 commit b536091
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/RequiredFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 ||
Expand Down

0 comments on commit b536091

Please sign in to comment.