Maybe just with SQL? INSERT using a SELECT. Wrap it in a transaction, so you can roll back.
But if that is a bit scary (or on a production box), just knock up some code in a controller to iterate through the temp table, then create them in the products table.
The best approach is to manage it using SQL.
If you are using a MySql DB, you can store information into temporary staging table, validate or clean what you need and then move all the information into the definitly table.
Code may change depending if you have one table per upload or you will manage an ID in 1 table for all the stagin uploads
DB::statement("Insert into table Select * from table_staging");
DB::commit();
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $table = env('TABLE_PRODUCTS');
}
.env
TABLE_PRODUCTS=products
Then I would try to change the .env to TABLE_PRODUCTS=product_staging when the excel has been saved successfully in the product_staging table
Is this approach possible?
another option is to use db triggers on the table and not use php at all. Just have the database do it automatically and copy from your staging table to the products table when it meets your criteria as for when it's 'completed'. It will just do it behind the scenes automatically and save system resources and less code.