A
A
abuamr2021-01-06 11:34:09
Laravel
abuamr, 2021-01-06 11:34:09

How to take tags only belonging to that model?

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

There is such structure of the table. The task is that when adding to the table videosin select, only tagsthose that belong to videos.

You can tagsadd typeand write the name of the table there and query scopesfilter through each model separately. But is there an easier way to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Talalaev, 2021-01-06
@neuotq

So what's the problem, everything is in the documentation, relation polymorph:
https://laravel.com/docs/8.x/eloquent-relationship...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question