Skip to content

Commit 9f53fd8

Browse files
committed
2.x
- Added API stack only
1 parent c98ec0c commit 9f53fd8

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/Commands/CrudGenerator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ protected function buildController(): static
137137
$this->buildLivewire();
138138

139139
return $this;
140-
} elseif ($this->options['stack'] == 'api') {
141-
$this->setControllerNamespace('App\Http\Controllers\Api');
142140
}
143141

144-
$controllerPath = $this->_getControllerPath($this->name);
142+
$controllerPath = $this->options['stack'] == 'api'
143+
? $this->_getApiControllerPath($this->name)
144+
: $this->_getControllerPath($this->name);
145145

146146
if ($this->files->exists($controllerPath) && $this->ask('Already exist Controller. Do you want overwrite (y/n)?', 'y') == 'n') {
147147
return $this;

src/Commands/GeneratorCommand.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ abstract class GeneratorCommand extends Command implements PromptsForMissingInpu
5454

5555
protected string $controllerNamespace = 'App\Http\Controllers';
5656

57+
protected string $apiControllerNamespace = 'App\Http\Controllers\Api';
58+
5759
protected string $resourceNamespace = 'App\Http\Resources';
5860

5961
protected string $livewireNamespace = 'App\Livewire';
@@ -178,6 +180,16 @@ protected function _getControllerPath($name): string
178180
return app_path($this->_getNamespacePath($this->controllerNamespace)."{$name}Controller.php");
179181
}
180182

183+
/**
184+
* @param $name
185+
*
186+
* @return string
187+
*/
188+
protected function _getApiControllerPath($name): string
189+
{
190+
return app_path($this->_getNamespacePath($this->apiControllerNamespace)."{$name}Controller.php");
191+
}
192+
181193
/**
182194
* @param $name
183195
*
@@ -272,6 +284,7 @@ protected function buildReplacements(): array
272284
'{{modelTitlePlural}}' => Str::title(Str::snake(Str::plural($this->name), ' ')),
273285
'{{modelNamespace}}' => $this->modelNamespace,
274286
'{{controllerNamespace}}' => $this->controllerNamespace,
287+
'{{apiControllerNamespace}}' => $this->apiControllerNamespace,
275288
'{{resourceNamespace}}' => $this->resourceNamespace,
276289
'{{requestNamespace}}' => $this->requestNamespace,
277290
'{{livewireNamespace}}' => $this->livewireNamespace,
@@ -590,9 +603,4 @@ protected function runCommands(array $commands): void
590603
$this->output->write(' '.$line);
591604
});
592605
}
593-
594-
protected function setControllerNamespace(string $controllerNamespace): void
595-
{
596-
$this->controllerNamespace = $controllerNamespace;
597-
}
598606
}

src/stubs/api/Controller.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace {{controllerNamespace}};
3+
namespace {{apiControllerNamespace}};
44

55
use {{modelNamespace}}\{{modelName}};
66
use Illuminate\Http\Request;

0 commit comments

Comments
 (0)