Skip to content

Commit cc26b32

Browse files
zeezo887ifox
authored andcommitted
load browsers into related cache when previewing blocks
1 parent 31dc84d commit cc26b32

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Helpers/BlockRenderer.php

+11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Exception;
1313
use Illuminate\Contracts\Support\Arrayable;
1414
use Illuminate\Database\Eloquent\Collection;
15+
use Illuminate\Database\Eloquent\Relations\Relation;
1516
use Illuminate\Support\Str;
1617

1718
/**
@@ -119,6 +120,16 @@ private static function getNestedBlocksForData(
119120

120121
$block->setRelation('children', self::getChildren($children));
121122

123+
foreach ($data['browsers'] as $browserName => $browserItems) {
124+
$browserData = collect();
125+
foreach ($browserItems as $browserItem) {
126+
$className = Relation::getMorphedModel($browserItem['endpointType']) ?? $browserItem['endpointType'];
127+
$browserData->push((new $className())->find($browserItem['id']));
128+
}
129+
130+
$block->setRelatedCache($browserName, $browserData);
131+
}
132+
122133
$block->medias = self::getMedias($data);
123134

124135
$class->setRenderData(

src/Models/Behaviors/HasRelated.php

+5
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,9 @@ public function clearAllRelated(): void
125125
{
126126
$this->relatedItems()->delete();
127127
}
128+
129+
public function setRelatedCache($browser, $items): void
130+
{
131+
$this->relatedCache[$browser] = $items;
132+
}
128133
}

0 commit comments

Comments
 (0)