@@ -78,8 +78,8 @@ public function prepareRelatedModels(): void
7878 $ content = $ this ->getModelContent ($ relation );
7979
8080 if ($ this ->shouldImportRelation ($ relation )) {
81- $ importRelation = $ this ->buildImportRelation ($ this ->model , $ this ->modelSubFolder );
82- $ this ->insertImport ($ content , $ importRelation );
81+ $ namespace = $ this ->generateClassNamespace ($ this ->model , $ this ->modelSubFolder );
82+ $ this ->insertImport ($ content , $ namespace );
8383 }
8484
8585 $ newRelation = $ this ->getStub ('relation ' , [
@@ -173,7 +173,7 @@ protected function getImportedRelations(): array
173173 foreach ($ this ->relations as $ relations ) {
174174 foreach ($ relations as $ relation ) {
175175 if ($ this ->shouldImportRelation ($ relation )) {
176- $ result [] = $ this ->buildImportRelation ($ relation );
176+ $ result [] = $ this ->generateClassNamespace ($ relation );
177177 }
178178 }
179179 }
@@ -183,17 +183,17 @@ protected function getImportedRelations(): array
183183
184184 protected function shouldImportRelation (string $ relation ): bool
185185 {
186- $ namespaceRelation = when (Str::contains ($ relation , '/ ' ), fn () => Str::beforeLast ($ relation , '/ ' ), '' );
186+ $ relationNamespace = when (Str::contains ($ relation , '/ ' ), fn () => Str::beforeLast ($ relation , '/ ' ), '' );
187187
188- return $ namespaceRelation != $ this ->modelSubFolder ;
188+ return $ relationNamespace != $ this ->modelSubFolder ;
189189 }
190190
191- protected function buildImportRelation (string $ relation , ?string $ subFolder = null ): string
191+ protected function generateClassNamespace (string $ className , ?string $ folder = null ): string
192192 {
193- $ importBase = $ this ->getOrCreateNamespace ('models ' , $ subFolder );
194- $ normalizedRelation = Str::replace ('/ ' , '\\' , $ relation );
193+ $ path = $ this ->getOrCreateNamespace ('models ' , $ folder );
194+ $ psrPath = Str::replace ('/ ' , '\\' , $ className );
195195
196- return "{$ importBase }\\{$ normalizedRelation }" ;
196+ return "{$ path }\\{$ psrPath }" ;
197197 }
198198
199199 protected function generateAnnotationProperties (array $ fields ): array
0 commit comments