我正在尝试使用MODEL FACTORY对我的数据库进行播种。我写了下面的代码。但是当我运行php artisan db:seed时,它显示:
[BadMethodCallException]
Call to undefined method Illuminate\Database\Query\Builder::fishes()
我的代码:
factory(App\Bear::class, 10)->create()->each(function($u) {
$u->fishes()->save(factory(App\Fish::class)->make());
});
任何帮助将不胜感激。 TIA ..
出于好奇:您的模型功能是公开的还是受保护的?
确保它们是公开的,例如:
public function historico()
{
return $this->hasMany('App\Historico', 'participante_id');
}
对我来说很好。