dbt / command-seeder
Command-based seeding for Laravel
Installs: 256
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
Requires
- php: ^8.1
- laravel/framework: ^8.0|^9.0|^10.0
Requires (Dev)
- ext-pcov: *
- laravel/pint: ^1.10
- orchestra/testbench: ^6.0|^7.0|^8.0
- phpunit/phpunit: ^9.0
README
An Artisan console command allows calling seeders with arguments.
Installation
composer require --dev dbt/command-seeder
Config
Publish the config file:
php artisan vendor:publish --provider="Dbt\CommandSeeder\CommandSeederServiceProvider" --tag="config"
Then populate the seeders
key with a map like so:
'seeders' => [ 'my-seeder' => MySeeder::class, ];
Seeders
Seeders must extend the CommandSeederAbstract
class. Each seeder must provide a list of arguments:
public function argumentNames(): ArgumentNames { return new ArgumentNames('firstArg', 'secondArg', 'etc'); }
These argument names will be matched up (by index) with the provided CLI arguments and will be passed into the run
method. If the number of required arguments doesn't match the number of given arguments, an exception will be thrown.
Additionally, the command's OutputStyle
is passed into the seeder's constructor so you can output to the console from the seeder:
public function run(Arguments $arguments, int $quantity): void { $firstArg = $arguments->get('firstArg'); $allArgs = $arguments->all(); // Create some models... $this->output->info('Write some output...'); }
Usage
php artisan seed:command {seederName} {quantity} {...arguments}