File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed
Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change 22
33namespace Code16 \OzuClient ;
44
5+ use Closure ;
6+ use Code16 \OzuClient \OzuCms \OzuCollectionConfig ;
57use Code16 \OzuClient \Support \Pagination \StaticLengthAwarePaginator ;
68use Code16 \OzuClient \Support \Pagination \StaticPaginator ;
79use Code16 \OzuClient \Support \Thumbnails \ImageKitThumbnail ;
@@ -86,9 +88,25 @@ public function boot()
8688 // Use Ozu's collectionKey as the morphMap key
8789 Relation::enforceMorphMap (
8890 collect (config ('ozu-client.collections ' ))
89- ->mapWithKeys (fn (string $ className ) => [
90- (new $ className ())->ozuCollectionKey () => $ className ,
91- ])
91+ ->map (fn ($ collection ) => match (true ) {
92+ is_string ($ collection ) => app ($ collection ),
93+ $ collection instanceof Closure => $ collection (),
94+ default => $ collection
95+ })
96+ ->map (function ($ model ) {
97+ $ sub = collect (
98+ $ model ::configureOzuCollection (new OzuCollectionConfig ())
99+ ->subCollections ()
100+ )->map (fn ($ subModel ) => match (true ) {
101+ is_string ($ subModel ) => app ($ subModel ),
102+ $ subModel instanceof Closure => $ subModel (),
103+ default => $ subModel
104+ });
105+
106+ return collect ([$ model ])->merge ($ sub );
107+ })
108+ ->flatten ()
109+ ->mapWithKeys (fn ($ class ) => [$ class ->ozuCollectionKey () => $ class ::class])
92110 ->toArray ()
93111 );
94112 }
You can’t perform that action at this time.
0 commit comments