Skip to content

Commit

Permalink
add new factory method
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Sep 12, 2020
1 parent e9d9b93 commit 4a95372
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Illuminate/Database/Eloquent/Factories/HasFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@ trait HasFactory
*/
public static function factory(...$parameters)
{
return Factory::factoryForModel(get_called_class())
$factory = static::newFactory() ?: Factory::factoryForModel(get_called_class());

return $factory
->count(is_numeric($parameters[0] ?? null) ? $parameters[0] : null)
->state(is_array($parameters[0] ?? null) ? $parameters[0] : ($parameters[1] ?? []));
}

/**
* Create a new factory instance for the model.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public static function newFactory()
{
//
}
}

0 comments on commit 4a95372

Please sign in to comment.