@@ -85,8 +85,8 @@ public function generate(): void
8585 'model ' => $ this ->model ,
8686 'fields ' => $ novaFields ,
8787 'types ' => array_unique (data_get ($ novaFields , '*.type ' )),
88- 'modelNamespace ' => $ this ->getNamespace ( ' models ' , $ this -> modelSubFolder ),
89- 'namespace ' => $ this ->getNamespace ('nova ' )
88+ 'imports ' => $ this ->getImports ( ),
89+ 'namespace ' => $ this ->getNamespace ('nova ' , $ this -> modelSubFolder ),
9090 ]);
9191
9292 $ this ->saveClass ('nova ' , "{$ this ->model }Resource " , $ fileContent , $ this ->modelSubFolder );
@@ -108,12 +108,12 @@ protected function prepareNovaFields(): array
108108 } else if (Arr::has ($ this ->specialFieldNamesMap , $ field ->name )) {
109109 $ result [$ field ->name ] = [
110110 'type ' => $ this ->specialFieldNamesMap [$ field ->name ],
111- 'is_required ' => $ field ->isRequired
111+ 'is_required ' => $ field ->isRequired ,
112112 ];
113113 } else {
114114 $ result [$ field ->name ] = [
115115 'type ' => $ fieldTypesMap [$ field ->type ],
116- 'is_required ' => $ field ->isRequired
116+ 'is_required ' => $ field ->isRequired ,
117117 ];
118118 }
119119 }
@@ -178,4 +178,17 @@ protected function getColumnList(string $table, ?string $connectionName = null):
178178 ->createSchemaManager ()
179179 ->listTableColumns ($ table );
180180 }
181+
182+ protected function getImports (): array
183+ {
184+ $ imports = [
185+ "{$ this ->getNamespace ('models ' , $ this ->modelSubFolder )}\\{$ this ->model }" ,
186+ ];
187+
188+ if (!empty ($ this ->modelSubFolder )) {
189+ $ imports [] = "{$ this ->getNamespace ('nova ' )}\\Resource " ;
190+ }
191+
192+ return $ imports ;
193+ }
181194}
0 commit comments