|
@@ -10,29 +10,37 @@ class AttributeProduct extends Model
|
|
|
use SoftDeletes;
|
|
|
protected $table = 'attribute_products';
|
|
|
protected $guarded = [];
|
|
|
- public function syncing($ids, $detaching = true)
|
|
|
+ public static function sync_attr(array $attributes = [])
|
|
|
{
|
|
|
- $changes = [
|
|
|
- 'attached' => [], 'detached' => [], 'updated' => [],
|
|
|
- ];
|
|
|
- $current = $this->getCurrentlyAttachedPivots()
|
|
|
- ->pluck($this->relatedPivotKey)->all();
|
|
|
- $detach = array_diff($current, array_keys(
|
|
|
- $records = $this->formatRecordsList($this->parseIds($ids))
|
|
|
- ));
|
|
|
- if ($detaching && count($detach) > 0) {
|
|
|
- $this->detach($detach);
|
|
|
+ $model = new static($attributes);
|
|
|
|
|
|
- $changes['detached'] = $this->castKeys($detach);
|
|
|
- }
|
|
|
- $changes = array_merge(
|
|
|
- $changes, $this->attachNew($records, $current, false)
|
|
|
- );
|
|
|
- if (count($changes['attached']) ||
|
|
|
- count($changes['updated'])) {
|
|
|
- $this->touchIfTouching();
|
|
|
- }
|
|
|
- return $changes;
|
|
|
+ $model->save();
|
|
|
+
|
|
|
+ return $model;
|
|
|
}
|
|
|
+// public function sync_attr($ids, $detaching = true)
|
|
|
+// {
|
|
|
+// $changes = [
|
|
|
+// 'attached' => [], 'detached' => [], 'updated' => [],
|
|
|
+// ];
|
|
|
+// $current = $this->getCurrentlyAttachedPivots()
|
|
|
+// ->pluck($this->relatedPivotKey)->all();
|
|
|
+// $detach = array_diff($current, array_keys(
|
|
|
+// $records = $this->formatRecordsList($this->parseIds($ids))
|
|
|
+// ));
|
|
|
+// if ($detaching && count($detach) > 0) {
|
|
|
+// $this->detach($detach);
|
|
|
+//
|
|
|
+// $changes['detached'] = $this->castKeys($detach);
|
|
|
+// }
|
|
|
+// $changes = array_merge(
|
|
|
+// $changes, $this->attachNew($records, $current, false)
|
|
|
+// );
|
|
|
+// if (count($changes['attached']) ||
|
|
|
+// count($changes['updated'])) {
|
|
|
+// $this->touchIfTouching();
|
|
|
+// }
|
|
|
+// return $changes;
|
|
|
+// }
|
|
|
}
|
|
|
|