如何将数据从一个 table 插入到 laravel 中的另一个?
How to insert data from one table to another in laravel?
我有两个 table,visitors
和 in
。
visitors
包含列 Name
、Number
、Purpose
和 Datetime
。
in
包含 Name
、Number
和 InTime
。
我想将 visitors
table 中的所有值提取到 in
中。我已尝试将数据从 visitors
复制到 in
,但是,如果我将新行添加到 visitors
table,这些新行将不会反映在我的 in
table.
有没有什么办法可以 copy/insert 从一个 table 到另一个 table 的所有数据,它也将反映 in
[=39] 中的新附加值=]?
当您在访问者中插入新行时,也将这些行插入 'in'
你不需要复制或其他东西。
你可以这样使用:
$copyNotificationTemplates = MasterNotificationTemplate::query()
->each(function ($template) use ($organizationId) {
$newTemplate = $template->replicate();
$newTemplate->setTable('notification_templates');
$newTemplate->organization_id = $organizationId;
$newTemplate->save();
});
我有两个 table,visitors
和 in
。
visitors
包含列 Name
、Number
、Purpose
和 Datetime
。
in
包含 Name
、Number
和 InTime
。
我想将 visitors
table 中的所有值提取到 in
中。我已尝试将数据从 visitors
复制到 in
,但是,如果我将新行添加到 visitors
table,这些新行将不会反映在我的 in
table.
有没有什么办法可以 copy/insert 从一个 table 到另一个 table 的所有数据,它也将反映 in
[=39] 中的新附加值=]?
当您在访问者中插入新行时,也将这些行插入 'in' 你不需要复制或其他东西。
你可以这样使用:
$copyNotificationTemplates = MasterNotificationTemplate::query()
->each(function ($template) use ($organizationId) {
$newTemplate = $template->replicate();
$newTemplate->setTable('notification_templates');
$newTemplate->organization_id = $organizationId;
$newTemplate->save();
});