diff --git a/README.md b/README.md index 3cd5e26..c7c78f9 100644 --- a/README.md +++ b/README.md @@ -256,6 +256,7 @@ Then run `php artisan ide-helper:generate`, you will now see all Fluent methods If you would like the `factory()->create()` and `factory()->make()` methods to return the correct model class, you can enable custom factory builders with the `include_factory_builders` line your `config/ide-helper.php` file. +Deprecated for Laravel 8 or latest. ```php 'include_factory_builders' => true, diff --git a/config/ide-helper.php b/config/ide-helper.php index 5386130..94118a6 100644 --- a/config/ide-helper.php +++ b/config/ide-helper.php @@ -45,6 +45,8 @@ return [ | Set to true to generate factory generators for better factory() | method auto-completion. | + | Deprecated for Laravel 8 or latest. + | */ 'include_factory_builders' => false, diff --git a/src/Factories.php b/src/Factories.php index 7038ede..97d91ef 100644 --- a/src/Factories.php +++ b/src/Factories.php @@ -12,18 +12,25 @@ class Factories { $factories = []; - $factory = app(Factory::class); + if (static::isLaravelSevenOrLower()) { + $factory = app(Factory::class); - $definitions = (new ReflectionClass(Factory::class))->getProperty('definitions'); - $definitions->setAccessible(true); + $definitions = (new ReflectionClass(Factory::class))->getProperty('definitions'); + $definitions->setAccessible(true); - foreach ($definitions->getValue($factory) as $factory_target => $config) { - try { - $factories[] = new ReflectionClass($factory_target); - } catch (Exception $exception) { + foreach ($definitions->getValue($factory) as $factory_target => $config) { + try { + $factories[] = new ReflectionClass($factory_target); + } catch (Exception $exception) { + } } } return $factories; } + + protected static function isLaravelSevenOrLower() + { + return class_exists('Illuminate\Database\Eloquent\Factory'); + } } diff --git a/tests/Factories/AllTest.php b/tests/Factories/AllTest.php new file mode 100644 index 0000000..f2608b5 --- /dev/null +++ b/tests/Factories/AllTest.php @@ -0,0 +1,18 @@ +