model::withoutEvents(function () { $this->model->categories()->sync($this->categories); $this->model->collections()->sync($this->collections); $this->model->inventories()->sync($this->inventories); if ($this->user->isAdmin()) { $this->model->channels()->sync($this->channel); } $attribute_ids = $this->properties ? DB::table('attributes')->whereIn('slug', array_keys($this->properties))->get(['id', 'type', 'slug']) : collect(); $attribute_ids->each(function ($attribute) { $productAttribute = ProductProperty::updateOrCreate([ 'product_id' => $this->model->id, 'attribute_id' => $attribute->id, ]); ProductAttributeValue::updateOrCreate(['product_attribute_id' => $productAttribute->id], [ 'attribute_value_id' => in_array($attribute->type, ['text', 'number']) ? null : $this->properties[$attribute->slug], 'product_custom_value' => in_array($attribute->type, ['text', 'number']) ? $this->properties[$attribute->slug] : null, ]); }); // sync properties json if (method_exists($this->model, 'syncPropertiesJson')) { $this->model->syncPropertiesJson(); } }); } }