44
55use FiveamCode \LaravelNotionApi \Entities \Blocks \Block ;
66use FiveamCode \LaravelNotionApi \Entities \Database ;
7+ use FiveamCode \LaravelNotionApi \Entities \Entity ;
78use FiveamCode \LaravelNotionApi \Entities \NotionParent ;
89use FiveamCode \LaravelNotionApi \Entities \Page ;
910use FiveamCode \LaravelNotionApi \Entities \Properties \Relation ;
1011use FiveamCode \LaravelNotionApi \Entities \User ;
1112use FiveamCode \LaravelNotionApi \Exceptions \HandlingException ;
1213use FiveamCode \LaravelNotionApi \Exceptions \NotionException ;
1314use FiveamCode \LaravelNotionApi \Notion ;
15+ use FiveamCode \LaravelNotionApi \Traits \HasParent ;
1416use Illuminate \Support \Collection ;
1517
1618/**
@@ -32,6 +34,8 @@ public function __construct(Notion $notion)
3234 }
3335
3436 /**
37+ * Resolve User
38+ *
3539 * @param User $user
3640 * @return User
3741 *
@@ -44,6 +48,26 @@ public function user(User $user): User
4448 }
4549
4650 /**
51+ * Resolve Parent of an entity
52+ *
53+ * @param Entity $entity
54+ * @return Page|Database|Block
55+ *
56+ * @throws HandlingException
57+ * @throws NotionException
58+ */
59+ public function parentOf (Entity $ entity )
60+ {
61+ if (!in_array (HasParent::class, class_uses_recursive (get_class ($ entity )))) {
62+ throw new HandlingException ("The given entity ' {$ entity ->getObjectType ()}' does not have a parent. " );
63+ }
64+
65+ return $ this ->parent ($ entity ->getParent ());
66+ }
67+
68+ /**
69+ * Resolve Parent
70+ *
4771 * @param NotionParent $parent
4872 * @return Page|Database|Block
4973 *
@@ -67,6 +91,8 @@ public function parent(NotionParent $parent): Page|Database|Block
6791 }
6892
6993 /**
94+ * Resolve Relations
95+ *
7096 * @param Relation $relation
7197 * @return Collection<Page>
7298 *
0 commit comments