HasFactory.php 861 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace Illuminate\Database\Eloquent\Factories;
  3. trait HasFactory
  4. {
  5. /**
  6. * Get a new factory instance for the model.
  7. *
  8. * @param callable|array|int|null $count
  9. * @param callable|array $state
  10. * @return \Illuminate\Database\Eloquent\Factories\Factory<static>
  11. */
  12. public static function factory($count = null, $state = [])
  13. {
  14. $factory = static::newFactory() ?: Factory::factoryForModel(get_called_class());
  15. return $factory
  16. ->count(is_numeric($count) ? $count : null)
  17. ->state(is_callable($count) || is_array($count) ? $count : $state);
  18. }
  19. /**
  20. * Create a new factory instance for the model.
  21. *
  22. * @return \Illuminate\Database\Eloquent\Factories\Factory<static>
  23. */
  24. protected static function newFactory()
  25. {
  26. //
  27. }
  28. }