Drummerkolle
1 month ago

Eloquent Has many over different models with index sort

Posted 1 month ago by Drummerkolle

Hi everybody,

I'm kind of stuck what to do for my use case, or better which relation to choose for it...

I want to have a table for multiple webpages (landingpages). Each page should have modules which are different types and tables (one should be text, one should be an image, one should be an entire different model, aso). I also need to order the modules and I tried to wrap my head around it but failed...

I think it should be something like an "inverse polymorphic many to many"?!?

Because I don't need one model, that can be used for multiple other models (like tags for posts or comments), but more like multiple models, that can be used on one model (the page)

Maybe it's just the normal polymorphic many to many and I just have thought to much about it and confused myself, but at this point I don't know anymore...

If I would go with that I would have the following tables:

landingpages module_images module_links module_text...

but what would be the relation table then?

landingpageable?

That just sounds so wrong...

I could then add an order column (index) to the landingpageable and call that from the landingpages model?!? Right now that I write this, it sounds kind of ok to me, but as said, I just don't know anymore...

Can someone confirm, that this would be the way to do it? Or give me a hint, what to do...

Thanks!

Please sign in or create an account to participate in this conversation.