mercredi 21 novembre 2018

Laravel Eloquent - Model - implementing database approach for tagging

Making a project using the Tag approach, The Tag could be inserted to Post, Comment or within Article from the blog.

having 4 tables tags, posts, comments, articles and the corresponding models are Tag, Post, Comment and Article.

the relationship between tags and each of posts, comments and articles would be many to many, so that 3 pivot tables will be created => tags_posts, tags_comments and tags_articles.

instead of creating 3 pivot tables, I decided to make it only one table to make it simpler, and this table have the structure =>

__Tag_Entries ____id ____tag_id ____related_type //(post, comment or article) ____related_id //(id of post, comment or article as per above type)

How to implement this approach in my Models ? Im using Laravel 5.7



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire