From 8ec3f78df52ccf4e1e51cbf121ca2b200deab2d6 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Fri, 10 May 2024 15:57:55 +1000 Subject: [PATCH] Adds withSyncSites to query --- src/Database/Scopes/MultisiteScope.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Database/Scopes/MultisiteScope.php b/src/Database/Scopes/MultisiteScope.php index b014dec71..97dc394fe 100644 --- a/src/Database/Scopes/MultisiteScope.php +++ b/src/Database/Scopes/MultisiteScope.php @@ -16,7 +16,7 @@ class MultisiteScope implements ScopeInterface /** * @var array extensions to be added to the builder. */ - protected $extensions = ['WithSite', 'WithSites']; + protected $extensions = ['WithSite', 'WithSites', 'WithSyncSites']; /** * apply the scope to a given Eloquent query builder. @@ -29,7 +29,7 @@ public function apply(BuilderBase $builder, ModelBase $model) } /** - * addWithSite + * addWithSite removes this scope and includes the specified site */ protected function addWithSite(BuilderBase $builder) { @@ -58,6 +58,16 @@ protected function addWithSites(BuilderBase $builder) }); } + /** + * addWithSyncSites removes this scope and includes sites that should be synced with this model + */ + protected function addWithSyncSites(BuilderBase $builder) + { + $builder->macro('withSyncSites', function (BuilderBase $builder) { + return $builder->withSites($builder->getModel()->getMultisiteSyncSites()); + }); + } + /** * extend the Eloquent query builder. */