Skip to content

Commit

Permalink
fix: return correct laravel version to compare correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
WatheqAlshowaiter committed Jul 15, 2024
1 parent f7f10ce commit 8b0a415
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions src/RequiredFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trait RequiredFields
*/
public static function getRequiredFields(): array
{
if (App::version() < 10) {
if ((float) App::version() < 10) {
return self::getRequiredFieldsForOlderVersions();
}

Expand All @@ -26,10 +26,11 @@ public static function getRequiredFields(): array
->toArray();

return collect(Schema::getColumns((new self())->getTable()))
->reject(fn ($column) => $column['auto_increment']
|| $column['nullable']
|| $column['default'] != null
|| in_array($column['name'], $primaryIndex)
->reject(
fn ($column) => $column['auto_increment']
|| $column['nullable']
|| $column['default'] != null
|| in_array($column['name'], $primaryIndex)
)
->pluck('name')
->toArray();
Expand Down Expand Up @@ -61,9 +62,10 @@ private static function getRequiredFieldsForSqlite(): array
$queryResult = array_map(fn ($column) => (array) $column, $queryResult);

return collect($queryResult)
->reject(fn ($column) => $column['pk']
|| $column['dflt_value']
|| ! $column['notnull']
->reject(
fn ($column) => $column['pk']
|| $column['dflt_value']
|| ! $column['notnull']
)
->pluck('name')
->toArray();
Expand All @@ -74,7 +76,8 @@ private static function getRequiredFieldsForMysqlAndMariaDb(): array

$table = self::getTableFromThisModel();

$queryResult = DB::select("
$queryResult = DB::select(
"
SELECT
COLUMN_NAME AS name,
COLUMN_TYPE AS type,
Expand All @@ -95,9 +98,10 @@ private static function getRequiredFieldsForMysqlAndMariaDb(): array
$queryResult = array_map(fn ($column) => (array) $column, $queryResult);

return collect($queryResult)
->reject(fn ($column) => $column['primary']
|| $column['default'] != null
|| $column['nullable']
->reject(
fn ($column) => $column['primary']
|| $column['default'] != null
|| $column['nullable']
)
->pluck('name')
->toArray();
Expand Down Expand Up @@ -147,7 +151,8 @@ private static function getRequiredFieldsForPostgres(): array
->flatten()
->toArray();

$queryResult = DB::select('
$queryResult = DB::select(
'
SELECT
is_nullable as nullable,
column_name as name,
Expand All @@ -165,9 +170,10 @@ private static function getRequiredFieldsForPostgres(): array
$queryResult = array_map(fn ($column) => (array) $column, $queryResult);

return collect($queryResult)
->reject(fn ($column) => $column['default']
|| $column['nullable'] == 'YES'
|| in_array($column['name'], $primaryIndex)
->reject(
fn ($column) => $column['default']
|| $column['nullable'] == 'YES'
|| in_array($column['name'], $primaryIndex)

)
->pluck('name')
Expand All @@ -182,7 +188,8 @@ private static function getRequiredFieldsForSqlServer(): array

$table = self::getTableFromThisModel();

$queryResult = DB::select("
$queryResult = DB::select(
"
SELECT
COLUMN_NAME AS name,
DATA_TYPE AS type,
Expand All @@ -204,9 +211,10 @@ private static function getRequiredFieldsForSqlServer(): array
$queryResult = array_map(fn ($column) => (array) $column, $queryResult);

return collect($queryResult)
->reject(fn ($column) => $column['primary']
|| $column['default'] != null
|| $column['nullable']
->reject(
fn ($column) => $column['primary']
|| $column['default'] != null
|| $column['nullable']
)
->pluck('name')
->toArray();
Expand Down

0 comments on commit 8b0a415

Please sign in to comment.