jeudi 14 juin 2018

Multi categories posts

I'm using laravel 5.6 and i have two tables categories and posts

I have created category_id in posts table which looks like

{id, category_id, title, description, created_at, updated_at}

I created a dropdown on the post create and edit form to select the category which works fine.

Now im looking for something more advanced where a post can have multiple categories. I have changed belongTo to HasMany categories in post model.

I feel im doing it the wrong way. Do i need to create another table i.e., post_categories {id, category_id, post_id}

The reason i want to do this is because i have multiple posts which belong to multiple categories and my route is like this

site.com/categoryname/post-slug

So few posts appear in multiple categories.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire