Skip to content

Commit

Permalink
load browsers into related cache when previewing blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
zeezo887 authored and ifox committed Oct 14, 2024
1 parent 31dc84d commit cc26b32
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Helpers/BlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Exception;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Str;

/**
Expand Down Expand Up @@ -119,6 +120,16 @@ private static function getNestedBlocksForData(

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

foreach ($data['browsers'] as $browserName => $browserItems) {
$browserData = collect();
foreach ($browserItems as $browserItem) {
$className = Relation::getMorphedModel($browserItem['endpointType']) ?? $browserItem['endpointType'];
$browserData->push((new $className())->find($browserItem['id']));
}

$block->setRelatedCache($browserName, $browserData);
}

$block->medias = self::getMedias($data);

$class->setRenderData(
Expand Down
5 changes: 5 additions & 0 deletions src/Models/Behaviors/HasRelated.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,9 @@ public function clearAllRelated(): void
{
$this->relatedItems()->delete();
}

public function setRelatedCache($browser, $items): void
{
$this->relatedCache[$browser] = $items;
}
}

0 comments on commit cc26b32

Please sign in to comment.