33namespace LaravelReady \ArtisanCommandPaletteUI \Http \Controllers ;
44
55use Illuminate \Http \Request ;
6- use Illuminate \Http \JsonResponse ;
76use Illuminate \Routing \Controller ;
87use Illuminate \Support \Facades \App ;
98use Illuminate \Support \Facades \Artisan ;
@@ -34,14 +33,14 @@ protected function getCommandGroups()
3433 $ commandGroups = Config::get ('artisan-command-palette-ui.command_groups ' , []);
3534 $ envRestrictions = Config::get ('artisan-command-palette-ui.environment_restricted_groups ' , []);
3635 $ currentEnv = App::environment ();
37-
36+
3837 // Apply environment restrictions
3938 foreach ($ envRestrictions as $ group => $ allowedEnvs ) {
4039 if (!in_array ($ currentEnv , $ allowedEnvs ) && isset ($ commandGroups [$ group ])) {
4140 $ commandGroups [$ group ] = [];
4241 }
4342 }
44-
43+
4544 return $ commandGroups ;
4645 }
4746
@@ -60,13 +59,13 @@ public function listCommands()
6059 // Return both predefined command groups and all available commands
6160 $ commandGroups = $ this ->getCommandGroups ();
6261 $ allCommands = $ this ->getAllCommands ();
63-
62+
6463 return Response::json ([
6564 'groups ' => $ commandGroups ,
6665 'all ' => $ allCommands ,
6766 ]);
6867 }
69-
68+
7069 /**
7170 * Get all available commands excluding the ones in the excluded list.
7271 *
@@ -112,7 +111,7 @@ protected function getAllCommands()
112111 public function executeCommand (Request $ request )
113112 {
114113 $ command = $ request ->input ('command ' );
115-
114+
116115 if (empty ($ command )) {
117116 return Response::json ([
118117 'success ' => false ,
@@ -126,8 +125,9 @@ public function executeCommand(Request $request)
126125 $ commandName = array_shift ($ parts );
127126 $ arguments = $ parts ;
128127
129- // Check if command exists
130- if (!Artisan::has ($ commandName )) {
128+ // Check if command exists - compatible with Laravel 8-12
129+ $ commands = Artisan::all ();
130+ if (!array_key_exists ($ commandName , $ commands )) {
131131 return Response::json ([
132132 'success ' => false ,
133133 'message ' => 'Error executing command ' ,
@@ -147,15 +147,13 @@ public function executeCommand(Request $request)
147147
148148 // Execute the command
149149 try {
150- ob_start ();
151- $ exitCode = Artisan::call ($ commandName , $ this ->parseArguments ($ arguments ));
152- $ output = ob_get_clean ();
150+ Artisan::call ($ command );
151+ $ output = Artisan::output ();
153152
154153 return Response::json ([
155154 'success ' => true ,
156155 'message ' => 'Command executed successfully ' ,
157156 'output ' => $ output ,
158- 'exit_code ' => $ exitCode
159157 ]);
160158 } catch (\Exception $ e ) {
161159 return Response::json ([
@@ -175,7 +173,7 @@ public function executeCommand(Request $request)
175173 protected function parseArguments (array $ arguments )
176174 {
177175 $ result = [];
178-
176+
179177 foreach ($ arguments as $ argument ) {
180178 if (strpos ($ argument , '= ' ) !== false ) {
181179 list ($ key , $ value ) = explode ('= ' , $ argument , 2 );
@@ -186,7 +184,7 @@ protected function parseArguments(array $arguments)
186184 $ result [] = $ argument ;
187185 }
188186 }
189-
187+
190188 return $ result ;
191189 }
192190}
0 commit comments