Skip to content

Commit

Permalink
Added support for Plural and Singular.
Browse files Browse the repository at this point in the history
  • Loading branch information
gent-fella-health committed Oct 8, 2020
1 parent 81145c5 commit 93bf4a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 14 additions & 5 deletions src/Console/ComponentMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;

class ComponentMakeCommand extends Command
{
Expand Down Expand Up @@ -158,6 +159,8 @@ protected function replaceClass($stub, $name, $fileName, $shortFileName)
$stub = str_replace('DummyVariable', $class, $stub);
$stub = str_replace('dummyVariable', lcfirst($class), $stub);
$stub = str_replace('dummyvariable', strtolower($class), $stub);
$stub = str_replace('Singular_Dummy_Variable', Str::singular(strtolower($class)), $stub);
$stub = str_replace('Plural_Dummy_Variable', Str::plural(strtolower($class)), $stub);
$stub = str_replace('DummyName', ucfirst($name), $stub);

return str_replace('DummyClass', $this->argument('name'). ucfirst($shortFileName), $stub);
Expand Down Expand Up @@ -210,13 +213,19 @@ public function handle()
{
$this->fire();

$routePath = $this->argument('name');
$routePath = strtolower($routePath);
$routePath = Str::plural($routePath);
$controllerName = $this->argument('name');
$controllerName = ucfirst($controllerName);

$this->info(
"Routes: ". PHP_EOL.
"$". "router->get('/". strtolower($this->argument('name')). "', '". ucfirst($this->argument('name')). "Controller@getAll');". PHP_EOL.
"$". "router->get('/". strtolower($this->argument('name')). "/{id}', '". ucfirst($this->argument('name')). "Controller@getById');". PHP_EOL.
"$". "router->post('/". strtolower($this->argument('name')). "', '". ucfirst($this->argument('name')). "Controller@create');". PHP_EOL.
"$". "router->put('/". strtolower($this->argument('name')). "/{id}', '". ucfirst($this->argument('name')). "Controller@update');". PHP_EOL.
"$". "router->delete('/". strtolower($this->argument('name')). "/{id}', '". ucfirst($this->argument('name')). "Controller@delete');". PHP_EOL
"$". "router->get('/". $routePath. "', '". $controllerName. "Controller@getAll');". PHP_EOL.
"$". "router->get('/". $routePath. "/{id}', '". $controllerName. "Controller@getById');". PHP_EOL.
"$". "router->post('/". $routePath. "', '". $controllerName. "Controller@create');". PHP_EOL.
"$". "router->put('/". $routePath. "/{id}', '". $controllerName. "Controller@update');". PHP_EOL.
"$". "router->delete('/". $routePath. "/{id}', '". $controllerName. "Controller@delete');". PHP_EOL
);
}
}
4 changes: 2 additions & 2 deletions src/Console/Stubs/controllers/controller.stub
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DummyClass extends Controller
$resourceOptions = $this->parseResourceOptions();

$data = $this->dummyVariableService->getAll($resourceOptions, true);
$parsedData = $this->parseData($data['rows'], $resourceOptions, 'rows');
$parsedData = $this->parseData($data['rows'], $resourceOptions, 'Plural_Dummy_Variable');
$parsedData['total_data'] = $data['total_data'];

return $this->response($parsedData);
Expand All @@ -32,7 +32,7 @@ class DummyClass extends Controller
$resourceOptions = $this->parseResourceOptions();

$data = $this->dummyVariableService->getById($dummyVariableId, $resourceOptions);
$parsedData = $this->parseData($data, $resourceOptions, 'row');
$parsedData = $this->parseData($data, $resourceOptions, 'Singular_Dummy_Variable');

return $this->response($parsedData);
}
Expand Down

0 comments on commit 93bf4a6

Please sign in to comment.