first upload all files
This commit is contained in:
41
Modules/Coupon/Entities/Concerns/SyncRelations.php
Normal file
41
Modules/Coupon/Entities/Concerns/SyncRelations.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Coupon\Entities\Concerns;
|
||||
|
||||
trait SyncRelations
|
||||
{
|
||||
protected function syncProducts($products)
|
||||
{
|
||||
$this->products()->sync(
|
||||
$this->makeSyncList($products, ['exclude' => false])
|
||||
);
|
||||
}
|
||||
|
||||
protected function syncExcludeProducts($excludeProducts)
|
||||
{
|
||||
$this->excludeProducts()->sync(
|
||||
$this->makeSyncList($excludeProducts, ['exclude' => true])
|
||||
);
|
||||
}
|
||||
|
||||
protected function syncCategories($categories)
|
||||
{
|
||||
$this->categories()->sync(
|
||||
$this->makeSyncList($categories, ['exclude' => false])
|
||||
);
|
||||
}
|
||||
|
||||
protected function syncExcludeCategories($excludeCategories)
|
||||
{
|
||||
$this->excludeCategories()->sync(
|
||||
$this->makeSyncList($excludeCategories, ['exclude' => true])
|
||||
);
|
||||
}
|
||||
|
||||
private function makeSyncList($items, $pivotData)
|
||||
{
|
||||
$pivotData = array_fill(0, count($items), $pivotData);
|
||||
|
||||
return array_combine($items, $pivotData);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user