我正在尝试在 Laravel 5.6.39 上制作php artisan db:se并收到错误消息:
BadMethodCallException:方法Illuminate \ Database \ Query \ Builder :: offers不存在。
优惠型号代码:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Offer extends Model
{
protected $guarded = [];
public function task()
{
return $this->belongsTo(Task::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
}
任务模型
public function offers()
{
return $this->hasMany(Offer::class);
}
数据库种子文件
factory(App\Task::class, 10)->create()->each(function ($task) {
return $task->offers()->save(factory(App\Offer::class)->make());
});
我在做什么不对?
答案 0 :(得分:-1)
将您的DatabaseSeeder更新为此并检查
factory(App\Task::class, 10)->create()->each(function ($task) {
return $task->offers()->save(factory(App\Offer::class)->create());
});