Is there a way to reduce many Insert queries to 1 when using Laravel's attach function in ManyToMany relationship?
Here is my code:
$itemIds = Item::pluck('id');
$sale = Sale::create();
foreach ($itemIds as $id) {
$sale->items()->attach($id);
}
But this way it makes as many queries as items found in the database.