问题描述
我正在使用带有 laravel-modules v2的Laravel 5.5.
I'm using Laravel 5.5 with laravel-modules v2.
很容易在自定义目录(特别是在模块内部)中生成迁移:
It's easy to generate migrations in a custom directory (inside a module, specifically):
php artisan make:migration create_users_table --path=Modules/User/Database/Migrations
但是似乎这对于种子类是不可能的:
But seems that this isn't possible with seeding classes:
php artisan make:seeder UsersTableSeeder --path=Modules/User/Database/
或传递完整的相对路径:
or passing full relative path:
php artisan make:seeder Modules/User/Database/Migrations/UsersTableSeeder
或传递完整的绝对路径:
or passing full absolute path:
php artisan make:seeder /Modules/User/Database/Migrations/UsersTableSeeder
如何在自定义目录中使用artisan命令生成播种器?
How to generate seeders with artisan command in a custom directory?
推荐答案
您不能. GeneratorCommand
(Seeder扩展)不关心文件夹是否存在,因为它仅用于写入文件.
You can't. The GeneratorCommand
(which the Seeder extends) doesn't care about whether or not folders exist, because it's just going to write the file only.
/**
* Get the destination class path.
*
* @param string $name
* @return string
*/
protected function getPath($name)
{
return $this->laravel->databasePath().'/seeds/'.$name.'.php';
}
实现所需目标的唯一方法是编写自己的Seeder
命令并允许目录遍历.您可以检查Illuminate\Database\Console\Migrations\MigrateMakeCommand
看看它是如何完成的,这不是很困难.
The only way to achieve what you want is to write your own Seeder
command and allow for directory traversal. You can inspect the Illuminate\Database\Console\Migrations\MigrateMakeCommand
to see how it's done, it's not very difficult.
这篇关于Laravel:如何在自定义目录中生成种子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!