Skip to content

Commit 6818737

Browse files
committed
Use closure for belongsTo relations as mentioned in #7
1 parent 5630bf1 commit 6818737

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Console/GenerateCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,9 @@ protected function getPropertiesFromMethods($model)
293293
$relatedObj = new $relatedModel;
294294

295295
$property = $relationObj->getForeignKey();
296-
$this->setProperty($property,'factory('.get_class($relationObj->getRelated()).'::class)->create()->'.$relatedObj->getKeyName());
296+
$this->setProperty($property,'function () {
297+
return factory('.get_class($relationObj->getRelated()).'::class)->create()->'.$relatedObj->getKeyName().';
298+
}');
297299
}
298300
}
299301
}
@@ -317,7 +319,7 @@ protected function setProperty($name, $type = null)
317319
$this->properties[$name]['type'] = $type;
318320
}
319321

320-
if (Str::startsWith($type,'factory(')) {
322+
if (Str::startsWith($type,'function ()')) {
321323
$this->properties[$name]['faker'] = true;
322324
}
323325

0 commit comments

Comments
 (0)