File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -106,6 +106,10 @@ public function withRelatedTitles(): self
106
106
*/
107
107
public function format (): array
108
108
{
109
+ if ($ this ->includeRelatedTitles ) {
110
+ $ this ->loadRelatedTitles ();
111
+ }
112
+
109
113
$ results = [];
110
114
111
115
foreach ($ this ->list as $ item ) {
@@ -115,6 +119,23 @@ public function format(): array
115
119
return $ results ;
116
120
}
117
121
122
+ /**
123
+ * Eager load the related book and chapter data when needed.
124
+ */
125
+ protected function loadRelatedTitles (): void
126
+ {
127
+ $ pages = collect ($ this ->list )->filter (fn ($ item ) => $ item instanceof Page);
128
+
129
+ foreach ($ this ->list as $ entity ) {
130
+ if (method_exists ($ entity , 'book ' )) {
131
+ $ entity ->load ('book ' );
132
+ }
133
+ if ($ entity instanceof Page && $ entity ->chapter_id ) {
134
+ $ entity ->load ('chapter ' );
135
+ }
136
+ }
137
+ }
138
+
118
139
/**
119
140
* Format a single entity item to a plain array.
120
141
*/
You can’t perform that action at this time.
0 commit comments