22
33namespace InfyOm \Generator \Commands \Publish ;
44
5+ use Illuminate \Support \Str ;
56use InfyOm \Generator \Utils \FileUtil ;
67use Symfony \Component \Console \Input \InputOption ;
78
@@ -28,6 +29,7 @@ class GeneratorPublishCommand extends PublishBaseCommand
2829 */
2930 public function handle ()
3031 {
32+ $ this ->updateRouteServiceProvider ();
3133 $ this ->publishTestCases ();
3234 $ this ->publishBaseController ();
3335 $ repositoryPattern = config ('infyom.laravel_generator.options.repository_pattern ' , true );
@@ -60,6 +62,27 @@ private function fillTemplate($templateData)
6062 return $ templateData ;
6163 }
6264
65+ private function updateRouteServiceProvider ()
66+ {
67+ $ routeServiceProviderPath = app_path ('Providers ' .DIRECTORY_SEPARATOR ."RouteServiceProvider.php " );
68+
69+ if (!file_exists ($ routeServiceProviderPath )) {
70+ $ this ->error ("Route Service provider not found on $ routeServiceProviderPath " );
71+ return 1 ;
72+ }
73+
74+ $ fileContent = file_get_contents ($ routeServiceProviderPath );
75+
76+ $ search = "Route::prefix('api') " .PHP_EOL .str (" " )->repeat (16 )."->middleware('api') " ;
77+ $ beforeContent = str ($ fileContent )->before ($ search );
78+ $ afterContent = str ($ fileContent )->after ($ search );
79+
80+ $ finalContent = $ beforeContent .$ search .PHP_EOL .str (" " )->repeat (16 )."->as('api.') " .$ afterContent ;
81+ file_put_contents ($ routeServiceProviderPath , $ finalContent );
82+
83+ return 0 ;
84+ }
85+
6386 private function publishTestCases ()
6487 {
6588 $ testsPath = config ('infyom.laravel_generator.path.tests ' , base_path ('tests/ ' ));
0 commit comments