helper.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. use think\migration\Factory;
  3. use think\migration\FactoryBuilder;
  4. if (!function_exists('factory')) {
  5. /**
  6. * Create a model factory builder for a given class, name, and amount.
  7. *
  8. * @param mixed class|class,name|class,amount|class,name,amount
  9. * @return FactoryBuilder
  10. */
  11. function factory()
  12. {
  13. /** @var Factory $factory */
  14. $factory = app(Factory::class);
  15. $arguments = func_get_args();
  16. if (isset($arguments[1]) && is_string($arguments[1])) {
  17. return $factory->of($arguments[0], $arguments[1])->times($arguments[2] ?? null);
  18. } elseif (isset($arguments[1])) {
  19. return $factory->of($arguments[0])->times($arguments[1]);
  20. }
  21. return $factory->of($arguments[0]);
  22. }
  23. }
  24. if (!function_exists('database_path')) {
  25. /**
  26. * 获取数据迁移脚本地址
  27. * @param string $path
  28. * @return string
  29. */
  30. function database_path($path = '')
  31. {
  32. return app()->getRootPath() . 'database' . DIRECTORY_SEPARATOR . $path;
  33. }
  34. }