diff --git a/README.md b/README.md index 0ef99f5..3ff5622 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ The Xeed is to generate new model, seed, database seed, factory and migration fi - [x] Database testing is supported - [x] Generate models for Laravel -- [ ] Generate seed files for Laravel -- [ ] Generate database seed files for Laravel +- [x] Generate seed files for Laravel +- [x] Generate database seed files for Laravel - [ ] Generate factories for Laravel - [ ] Generate migrations for Laravel @@ -41,6 +41,20 @@ bin/console models # Generate all models from database in `dist/app/Models` folder ``` +### Generate `Seeder`s + +```sh +bin/console seeders +# Generate all seeds from database in `dist/database/seeders` folder +``` + +### Generate `DatabaseSeeder` + +```sh +bin/console database +# Generate database seed from database in `dist/database/seeders` folder +``` + ## How to contribute ### Development diff --git a/bin/console b/bin/console index 69544e6..9bd5903 100755 --- a/bin/console +++ b/bin/console @@ -3,6 +3,7 @@ require __DIR__.'/../vendor/autoload.php'; +use Cable8mm\Xeed\Command\GenerateDatabaseSeederCommand; use Cable8mm\Xeed\Command\GenerateModelsCommand; use Cable8mm\Xeed\Command\GenerateSeedersCommand; use Symfony\Component\Console\Application; @@ -13,5 +14,6 @@ $application = new Application(); $application->add(new GenerateModelsCommand()); $application->add(new GenerateSeedersCommand()); +$application->add(new GenerateDatabaseSeederCommand()); $application->run(); diff --git a/src/Command/GenerateDatabaseSeederCommand.php b/src/Command/GenerateDatabaseSeederCommand.php new file mode 100644 index 0000000..8db0dbc --- /dev/null +++ b/src/Command/GenerateDatabaseSeederCommand.php @@ -0,0 +1,46 @@ +safeLoad(); + } + + /** + * Generate models. + * + * Run `bin/console generate-seeders` or `bin/console seeders` + */ + protected function execute(InputInterface $input, OutputInterface $output): int + { + $tables = DB::getInstance()->attach()->getTables(); + + $classes = []; + + foreach ($tables as $table) { + $classes[] = Inflector::classify($table->name); + } + + DatabaseSeederGenerator::make($classes)->run(); + + return Command::SUCCESS; + } +}