我正在尝试将任务与TODO列表关联,但是当我通过修补程序应用此代码时:
$list = Todolist::find(245);
$task = new Task;
$task->name = 'Walk the dog';
$task->description = 'Walk Barky the Mutt';
$list->tasks()->save($task);
我有一个错误:在null
上调用成员函数tasks()Todolist模特
public function tasks()
{
return $this->hasMany('App\Task');
}
任务模型
public function todolist()
{
return $this->belongsTo('App\Todolist');
}