Add company_id column to media tables

This commit is contained in:
Burak Çakırel
2021-05-17 22:32:45 +03:00
parent bdb51a27a4
commit d13e41f6df
7 changed files with 140 additions and 20 deletions

View File

@ -34,4 +34,26 @@ trait Media
return $media;
}
public function attachMedia($media, $tags): void
{
$tags = (array)$tags;
$increments = $this->getOrderValueForTags($tags);
$ids = $this->extractPrimaryIds($media);
foreach ($tags as $tag) {
$attach = [];
foreach ($ids as $id) {
$attach[$id] = [
'company_id' => company_id(),
'tag' => $tag,
'order' => ++$increments[$tag],
];
}
$this->media()->attach($attach);
}
$this->markMediaDirty($tags);
}
}