Skip to content

Commit 0f180a9

Browse files
committed
Merge branch 'feature/resolve' into feature/notion-models-and-commands
2 parents f828d7d + 3c9c845 commit 0f180a9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/Endpoints/Resolve.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
namespace FiveamCode\LaravelNotionApi\Endpoints;
44

55
use FiveamCode\LaravelNotionApi\Entities\Blocks\Block;
6+
use FiveamCode\LaravelNotionApi\Entities\Collections\PageCollection;
67
use FiveamCode\LaravelNotionApi\Entities\Database;
78
use FiveamCode\LaravelNotionApi\Entities\NotionParent;
89
use FiveamCode\LaravelNotionApi\Entities\Page;
10+
use FiveamCode\LaravelNotionApi\Entities\Properties\Relation;
911
use FiveamCode\LaravelNotionApi\Entities\User;
1012
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
1113
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
1214
use FiveamCode\LaravelNotionApi\Notion;
15+
use Illuminate\Support\Collection;
1316

1417
/**
1518
* Class Resolve.
@@ -63,4 +66,29 @@ public function parent(NotionParent $parent): Page|Database|Block
6366
throw new HandlingException('Unknown parent type while resolving the notion parent');
6467
}
6568
}
69+
70+
/**
71+
* @param Relation $relation
72+
* @return Collection<Page>
73+
*
74+
* @throws HandlingException
75+
* @throws NotionException
76+
*/
77+
public function relations(Relation $relation, bool $onlyTitles = false): Collection
78+
{
79+
$pages = collect();
80+
$relationIds = $relation->getRelation()->map(function ($o) {
81+
return $o['id'];
82+
});
83+
84+
foreach ($relationIds as $relationId) {
85+
if ($onlyTitles) {
86+
$pages->add($this->notion->pages()->find($relationId)->getTitle());
87+
} else {
88+
$pages->add($this->notion->pages()->find($relationId));
89+
}
90+
}
91+
92+
return $pages;
93+
}
6694
}

0 commit comments

Comments
 (0)