1

Take a many-to-many polymorphic relationship sample from the Laravel docs website.

posts
    id - integer
    name - string

videos
    id - integer
    name - string

tags
    id - integer
    name - string

taggables
    tag_id - integer
    taggable_id - integer
    taggable_type - string
    extra_column_a - string
    extra_column_b - integer

How to insert data into the extra_column_a and extra_column_b column when creating a post/video with tag or when creating a tag with post/video?

Do I need to create a model class for the taggables table when it has extra columns?

O Connor
  • 4,236
  • 15
  • 50
  • 91

1 Answers1

0

Maybe something like this. Second parametr in arr

$video->tags()->attach($t, ['extra_column_a'=>'custstring','extra_column_b'=>'asd']);
gluktd
  • 46
  • 5
  • Can I find it somewhere in the docs or do I have to dive into the base model class to discover such methods? – O Connor Aug 27 '20 at 07:33
  • No, it's not mentioned in the docs. It's just like typically with many/many relations – gluktd Aug 27 '20 at 07:36