You need to use associate() on a Builder instance (i.e. the method, not a relation result) on a BelongsTo relationship:
$model->related()->associate($other);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
So Eloquent's attach() method is for many-to-many situations; and I am using that without issue.
The equivalent for 1-to-many relationships appears to be associate(), but I can not get this to work. (failing with either "undefined method" or it doesn't auto add the foreign key.) I am able to simply use $singleModel->manyRelatedModels->save(new RelatedModel()) instead.
But I'm curious and wondering if anybody can shed any light on the associate() method?
Best regards, Dev Master
You need to use associate() on a Builder instance (i.e. the method, not a relation result) on a BelongsTo relationship:
$model->related()->associate($other);
Please or to participate in this conversation.