给定命名空间,我假设您正在使用Asgard CMS,并且您已将 Insuree 模型工厂放在模块的工厂目录中。这不起作用,因为默认情况下 Model Factories 的查找固定为database_path('factories')
,请参见 Factory 类中的以下内容:
/**
* Create a new factory container.
*
* @param \Faker\Generator $faker
* @param string|null $pathToFactories
* @return static
*/
public static function construct(Faker $faker, $pathToFactories = null)
{
$pathToFactories = $pathToFactories ?: database_path('factories');
return (new static($faker))->load($pathToFactories);
}
将模块工厂移动到项目的工厂目录:
<PROJECT>/
├── database/
│ └── factories/
│ └── InsureeFactory.php
└── Modules/
&然后重新运行你的播种机:
namespace Modules\Brokerquotes\Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class BrokerquotesDatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
factory(\Modules\Brokerquotes\Entities\Insuree::class, 5)->create();
}
}
工匠命令:
php artisan db:seed --class=Modules\\Brokerquotes\\Database\\Seeders\\BrokerquotesDatabaseSeeder