php - How to insert data from one table to another in laravel?

Solution:

You can use something like this :

$copyNotificationTemplates = MasterNotificationTemplate::query()
                                    ->each(function ($template) use ($organizationId) {
                                    $newTemplate = $template->replicate();
                                    $newTemplate->setTable('notification_templates');
                                    $newTemplate->organization_id = $organizationId;
                                    $newTemplate->save();
                                });

Answer

Solution:

When you insert new rows in visitors, insert that rows in 'in' too so you don't need to copy or other things.

Source