@@ -60,7 +60,7 @@ public function configure(): void
6060 public function execute ( array $ Parameters = [] ): int
6161 {
6262 $ this ->output ->info ( "\n╔═══════════════════════════════════════╗ " );
63- $ this ->output ->info ( "║ MVC Controller Generator ║ " );
63+ $ this ->output ->info ( "║ MVC Controller Generator ║ " );
6464 $ this ->output ->info ( "╚═══════════════════════════════════════╝ \n" );
6565
6666 // Get controller name
@@ -315,34 +315,37 @@ private function generateRoutes( array $info ): bool
315315 }
316316 $ controller = $ namespace . '\\' . $ info ['class ' ];
317317
318- // Build routes
318+ // Generate route name prefix (e.g., "posts" or "admin_posts")
319+ $ routeNamePrefix = strtolower ( str_replace ( '/ ' , '_ ' , $ info ['controllerPath ' ] ) );
320+
321+ // Build routes with named keys
319322 $ newRoutes = [
320- [
323+ $ routeNamePrefix . ' _index ' => [
321324 'method ' => 'GET ' ,
322325 'route ' => $ info ['routePrefix ' ],
323326 'controller ' => $ controller . '@index ' ,
324327 ],
325- [
328+ $ routeNamePrefix . ' _create ' => [
326329 'method ' => 'GET ' ,
327330 'route ' => $ info ['routePrefix ' ] . '/create ' ,
328331 'controller ' => $ controller . '@create ' ,
329332 ],
330- [
333+ $ routeNamePrefix . ' _store ' => [
331334 'method ' => 'POST ' ,
332335 'route ' => $ info ['routePrefix ' ],
333336 'controller ' => $ controller . '@store ' ,
334337 ],
335- [
338+ $ routeNamePrefix . ' _edit ' => [
336339 'method ' => 'GET ' ,
337340 'route ' => $ info ['routePrefix ' ] . '/:id/edit ' ,
338341 'controller ' => $ controller . '@edit ' ,
339342 ],
340- [
343+ $ routeNamePrefix . ' _update ' => [
341344 'method ' => 'PUT ' ,
342345 'route ' => $ info ['routePrefix ' ] . '/:id ' ,
343346 'controller ' => $ controller . '@update ' ,
344347 ],
345- [
348+ $ routeNamePrefix . ' _destroy ' => [
346349 'method ' => 'DELETE ' ,
347350 'route ' => $ info ['routePrefix ' ] . '/:id ' ,
348351 'controller ' => $ controller . '@destroy ' ,
@@ -352,11 +355,28 @@ private function generateRoutes( array $info ): bool
352355 // Add show route for API controllers
353356 if ( $ info ['isApi ' ] )
354357 {
355- array_splice ( $ newRoutes , 1 , 0 , [[
356- 'method ' => 'GET ' ,
357- 'route ' => $ info ['routePrefix ' ] . '/:id ' ,
358- 'controller ' => $ controller . '@show ' ,
359- ]]);
358+ // Insert show route after index, before create
359+ $ showRoute = [
360+ $ routeNamePrefix . '_show ' => [
361+ 'method ' => 'GET ' ,
362+ 'route ' => $ info ['routePrefix ' ] . '/:id ' ,
363+ 'controller ' => $ controller . '@show ' ,
364+ ]
365+ ];
366+
367+ // Merge in the correct position
368+ $ routesArray = [];
369+ $ inserted = false ;
370+ foreach ( $ newRoutes as $ key => $ route )
371+ {
372+ $ routesArray [$ key ] = $ route ;
373+ if ( $ key === $ routeNamePrefix . '_index ' && !$ inserted )
374+ {
375+ $ routesArray = array_merge ( $ routesArray , $ showRoute );
376+ $ inserted = true ;
377+ }
378+ }
379+ $ newRoutes = $ routesArray ;
360380 }
361381
362382 // Add filter if specified
0 commit comments