Set up many to many relationship in laravel eloquent

前端 未结 3 745
温柔的废话
温柔的废话 2021-01-27 08:59

What is the best practice to setup many to many relationship with post and categories in laravel eloquent? Do I create a separate model for pivot table?

This is how I de

3条回答
  •  无人共我
    2021-01-27 10:02

    To define this relationship, three database tables are needed: post, category, and category_post. The category_post table is derived from the alphabetical order of the related model names, and contains the category_id and post_id columns.

提交回复
热议问题