You already store the created_by and updated_by on products, would not mean there is any need to have it on the pivot_table, just seems messy, also I personally like to have a little disturbance as possible, which means you could also just remove the id column if you wish.
Jul 24, 2017
2
Level 1
Defining database tables and it's pivot table
Products are created by users. Products can be updated by other users as well. And I want to list them like below:
id product created_by updated_by
1 milk John Doe John Doe
2 biscuit Alex Tiger John Doe
3 chocolate John Doe Alex Tiger
Now, how to define use pivot table?
products table
------------------
id product created_by updated_by
1 milk 1 1
2 biscuit 2 1
3 chocolate 1 2
pivot table
---------------
id product_id user_id
Or,
products table
------------------
id product
1 milk
2 biscuit
3 chocolate
pivot table
---------------
id product_id user_id created_by updated_by
It would be my pleasure if you could show me the code for view and the controller as well.
Please help me. Thanks.
Please or to participate in this conversation.