我可以创建种子组吗?例如,我有一些我只想在某些时候执行的种子。执行时如何添加标志php artisan migrate --seed --group1
我对此类功能有哪些选择?
Well, what you could do is create multiple Seeder
extended classes, and having each one of them running $this->call()
on a specific group of tables and then specify which one you want using the --class
flag. Something like this:
class GroupOneDatabaseSeeder extends Seeder {
public function run() {
Eloquent::unguard();
$this->call('UserTableSeeder');
$this->call('RoleTableSeeder');
}
}
And then call it this way:
php artisan db:seed --class="GroupOneDatabaseSeeder"
Well, that or you could extend the SeedCommand
to add this functionality via methods instead of classes.