Level 88
MorphToMany extends the BelongsToMany relationship so you should have the sync method available here as well.
$blog = Blog:::first();
$blog->tags()->sync([1, ,2, 3]);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi I have 3 tables that they're in morphmany relationship and this is my models:
class Blog extends BasicModel
{
public function tags(): MorphToMany
{
return $this->morphToMany(Tag::class , 'taggable' , 'taggables');
}
}
class Tag extends BasicModel
{
protected $fillable = ['name'];
public function blogs(): MorphToMany
{
return $this->morphedByMany(Blog::class , 'taggable' , 'taggables');
}
}
Is there any way to save tags and sync them by blog model in one line, like the original sync method??
Please or to participate in this conversation.