diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index caebed731..675cbcfab 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -777,6 +777,14 @@ protected function isRelationNullable(string $relation, Relation $relationObj): $fkProp->setAccessible(true); if ($relation === 'belongsTo') { + if (is_array($fkProp->getValue($relationObj))) { + return (bool) \Illuminate\Support\Arr::first( + (array)$fkProp->getValue($relationObj), + fn (string $value) => isset($this->nullableColumns[$value]) || + !in_array($value, $this->foreignKeyConstraintsColumns, true) + ); + } + return isset($this->nullableColumns[$fkProp->getValue($relationObj)]) || !in_array($fkProp->getValue($relationObj), $this->foreignKeyConstraintsColumns, true); }