S
S
skarietsky2018-05-07 20:13:49
Laravel
skarietsky, 2018-05-07 20:13:49

Many-to-many relationship with many tables?

Hello.
The site has news, videos, galleries, people. All entities have tags. Now there are 4, but there may be more.
I'd like to create one table where I link them to a tag. The tag table is common to all.
Like this:
| id | material_id | tag_id | material_type |
|.1.|.........1.........|.....1....|........news..... ..|
|.2.|.........1.........|.....1....|........video..... ..|
|.3.|.........1.........|.....1....|.......gallery...... |
I tried to do this, but I ran into a key constraint - I don't know how to set a foreign key for an intermediate table.
How to register a foreign key on n tables?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yan-s, 2018-05-07
@skarietsky

https://laravel.ru/docs/v5/eloquent-relationships#mmp

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question