Php Laravel HasMany没有附加或关联方法?

Php Laravel HasMany没有附加或关联方法?,php,laravel,relationship,Php,Laravel,Relationship,我将关系存储在变量中: $relation = $model->{$relationConfig['relation']}(); 然后我确定它确实有很多关系: dd($relation); 我看到了。然后,我就这样使用它: $relation->associate($newModel); 然后这个错误发生了: Call to undefined method Illuminate\Database\Eloquent\Relations\HasMany::associate()

我将关系存储在变量中:

$relation = $model->{$relationConfig['relation']}();
然后我确定它确实有很多关系:

dd($relation);
我看到了。然后,我就这样使用它:

$relation->associate($newModel);
然后这个错误发生了:

Call to undefined method Illuminate\Database\Eloquent\Relations\HasMany::associate()

我在这里做错了什么?

我知道我可以使用child的belongsTo关系,但我不想在config中存储反向关系名称…然后使用$relation->hasMany()->save($newModel);我知道我可以使用child的belongsTo关系,但我不想在config中存储反向关系名称…然后使用$relation->hasMany()->save($newModel);
$newModel = new Child([
  'column' => 'value',
])
$relation = Parent::create([
  'column' => 'value'
]);
$newModel->belongsToRelation()->associate($relation);
$newModel->save();
//or
$relation = Parent::find(1)->hasMany()->create([
  'column' => 'value'
]);