Skip to content

Commit

Permalink
Check for method existence
Browse files Browse the repository at this point in the history
  • Loading branch information
btaskew committed Sep 24, 2020
1 parent 6321ae0 commit 70a73ab
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/Illuminate/Database/Eloquent/Factories/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,9 @@ public function __call($method, $parameters)

$relationshipClass = get_class($this->newModel()->{$relationship}()->getRelated());

$factory = $relationshipClass::newFactory() ?: static::factoryForModel($relationshipClass);
$factory = method_exists($relationshipClass, 'newFactory') && $relationshipClass::newFactory()
? $relationshipClass::newFactory()
: static::factoryForModel($relationshipClass);

if (Str::startsWith($method, 'for')) {
return $this->for($factory->state($parameters[0] ?? []), $relationship);
Expand Down
6 changes: 0 additions & 6 deletions tests/Database/DatabaseEloquentFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,6 @@ public function definition()

class FactoryTestPost extends Eloquent
{
use HasFactory;

protected $table = 'posts';

public function user()
Expand Down Expand Up @@ -435,8 +433,6 @@ public function definition()

class FactoryTestComment extends Eloquent
{
use HasFactory;

protected $table = 'comments';

public function commentable()
Expand All @@ -459,8 +455,6 @@ public function definition()

class FactoryTestRole extends Eloquent
{
use HasFactory;

protected $table = 'roles';

public function users()
Expand Down

0 comments on commit 70a73ab

Please sign in to comment.