I'm trying to use pivot table. But I'm confused how should I define my database tables.
Concept: Packages are created by users. Packages can be modified by other users as well.
So, should I define like this?
Customers table
---------------
id
package_name
created_by
updated_by
Pivot table
------------
id
customer_id
user_id
Or,
Customers table
---------------
id
package_name
Pivot table
------------
id
customer_id
user_id
created_by
updated_by
I would like the result like this:
id package_name created_by updated_by
1 one user1 user1
2 two user1 user2
3 three user2 user2
Please help. I am trying to learn about pivot from many days.
Is it only ever going to be created_by
and updated_by
? What happens if multiple users update the package, you only want to track the person who updated it last?
If so, then your design can just be this without the need for a pivot table:
Customers
-----------
id
name
Packages
-----------
id
name
created_by (customer_id)
updated_by (customer_id)
However, if you'd like to track all users that update a package, you could do something like this:
Customers
-----------
id
name
Packages
-----------
id
name
created_by (customer_id)
Pivot (tracking updates)
-----------
customer_id (primary key)
package_id (primary key)
updated_at (timestamp)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community