【发布时间】:2021-08-03 14:06:13
【问题描述】:
我想知道如何用所有可能的值填充数据透视表。
我有一个用户表:
//users table
id | name
一个 notification_preferences 表:
//notification_preferences table
id | name
还有一个枢轴 user_notification_preference
//user_notification_preference
id | user_id | notification_preference_id | is_enabled
我想用所有现有的 notification_preference 填充我的数据透视表,并将 is_enabled 值设置为 true,并且,当我创建新的 notification_preference 时,它应该再次同步到它,并将 is_enabled 值设置为 true。
有没有通用的方法呢?
【问题讨论】:
-
我不知道我是否明白你在问什么......你想在什么时候用所有现有的 notification_preference 填充数据透视表?要将 is_enabled 值默认设置为 true,您可以在 DB 级别使用
->default(1)设置该列
标签: laravel pivot-table