How to use toggle column to update pivot table?
I have a many-to-many relationship with product, user, and product_user_fav models, and I want to create a favorite toggle column in the products table to update the product_user_fav table (pivot).
That is when a user switches the favorite toggle column in the products table if there are no user_id and product_id rows in the Product_user_fav table, a new row is registered in the pivot table, and if there are user_id and product_id, the existing row is removed.
How can I do this? Thank you!
#user model
#product model
#product_user_fav model
#produts table
That is when a user switches the favorite toggle column in the products table if there are no user_id and product_id rows in the Product_user_fav table, a new row is registered in the pivot table, and if there are user_id and product_id, the existing row is removed.
How can I do this? Thank you!
#user model
#product model
#product_user_fav model
#produts table
