Product::all()->each(function($product) {
$productCategories = $categoriesProductMap[$product->vendor_code];
$categoryIds = Category::whereIn('name', $productCategories)->select('id')->get()->pluck('id');
$product->categories()->syncWithoutDetaching($categoryIds);
})