Reputation: 1220
Assume we have one to many relationship like post
and comment
, each post hasMany
comments and each comment belongsTo
one post.
The question is how we could call associate
method?
in Laravel document the associate
method is called on relation method, something like:
$comment = new Comment(['title' => 'something']);
$post->comments()->associate($comment);
but in some cases, I saw the associate
method is called on relation attribute like:
$comment = new Comment(['title' => 'something']);
$post->comments->associate($comment);
Are they the same? is there any difference between them?
Thanks
Upvotes: 0
Views: 656