@@ -124,6 +124,7 @@ public function handle(): void
124124 $ this ->checkConfigs ();
125125 $ this ->listenEvents ();
126126 $ this ->parseRelations ();
127+ $ this ->entityName = $ this ->convertToPascalCase ($ this ->entityName );
127128
128129 try {
129130 $ this ->generate ();
@@ -238,19 +239,20 @@ protected function getCrudOptions(): array
238239 protected function parseRelations (): void
239240 {
240241 $ this ->relations = new RelationsDTO (
241- hasOne: $ this ->trimRelations ($ this ->option ('has-one ' )),
242- hasMany: $ this ->trimRelations ($ this ->option ('has-many ' )),
243- belongsTo: $ this ->trimRelations ($ this ->option ('belongs-to ' )),
244- belongsToMany: $ this ->trimRelations ($ this ->option ('belongs-to-many ' )),
242+ hasOne: $ this ->prepareRelations ($ this ->option ('has-one ' )),
243+ hasMany: $ this ->prepareRelations ($ this ->option ('has-many ' )),
244+ belongsTo: $ this ->prepareRelations ($ this ->option ('belongs-to ' )),
245+ belongsToMany: $ this ->prepareRelations ($ this ->option ('belongs-to-many ' )),
245246 );
246247 }
247248
248- protected function trimRelations (array $ relations ): array
249+ protected function prepareRelations (array $ relations ): array
249250 {
250- return array_map (
251- callback: fn ($ relation ) => Str::trim ($ relation , '/ ' ),
252- array: $ relations ,
253- );
251+ return array_map (function ($ relation ) {
252+ $ relation = Str::trim ($ relation , '/ ' );
253+
254+ return $ this ->convertToPascalCase ($ relation );
255+ }, $ relations );
254256 }
255257
256258 protected function getFields (): array
@@ -305,4 +307,15 @@ protected function listenEvents(): void
305307 listener: fn (WarningEvent $ event ) => $ this ->warn ($ event ->message ),
306308 );
307309 }
310+
311+ protected function convertToPascalCase (string $ entityName ): string
312+ {
313+ $ pascalEntityName = Str::studly ($ entityName );
314+
315+ if ($ entityName !== $ pascalEntityName ) {
316+ $ this ->info ("{$ entityName } was converted to {$ pascalEntityName }" );
317+ }
318+
319+ return $ pascalEntityName ;
320+ }
308321}
0 commit comments