Skip to content

Commit 1917088

Browse files
committed
Add method to get nullable attributes
1 parent 81f3df2 commit 1917088

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Traits/NullableAttributesTrait.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,16 @@ public function setAttribute($key, $val)
5151
}
5252
return parent::setAttribute($key, $val);
5353
}
54+
55+
/**
56+
* @param null $modelName
57+
* @return array
58+
*/
59+
public function getNullableAttributes($modelName = null): array
60+
{
61+
if (null !== $modelName) {
62+
return self::$nullableAttributes[$modelName] ?? [];
63+
}
64+
return self::$nullableAttributes;
65+
}
5466
}

src/helpers.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ function get_model_nullable_attributes(string $modelName): array
2424
$reflection->isSubclassOf(\Illuminate\Database\Eloquent\Model::class)
2525
) {
2626
$model = new $modelName;
27-
if (isset($model::$nullableAttributes[$modelName])) {
28-
return $model::$nullableAttributes[$modelName];
27+
$nullableAttributes = $model->getNullableAttributes($modelName);
28+
if (!empty($nullableAttributes)) {
29+
return $nullableAttributes;
2930
}
3031
$table = $model->getTable();
3132
/** @var array $columns */

0 commit comments

Comments
 (0)