Skip to content

Commit

Permalink
Change string functions with class methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sohelamin committed Sep 21, 2019
1 parent 0f6ef59 commit b66c400
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
7 changes: 4 additions & 3 deletions src/Commands/CrudApiCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

class CrudApiCommand extends Command
{
Expand Down Expand Up @@ -59,12 +60,12 @@ public function __construct()
public function handle()
{
$name = $this->argument('name');
$modelName = str_singular($name);
$migrationName = str_plural(snake_case($name));
$modelName = Str::singular($name);
$migrationName = Str::plural(Str::snake($name));
$tableName = $migrationName;

$routeGroup = $this->option('route-group');
$this->routeName = ($routeGroup) ? $routeGroup . '/' . snake_case($name, '-') : snake_case($name, '-');
$this->routeName = ($routeGroup) ? $routeGroup . '/' . Str::snake($name, '-') : Str::snake($name, '-');
$perPage = intval($this->option('pagination'));

$controllerNamespace = ($this->option('controller-namespace')) ? $this->option('controller-namespace') . '\\' : '';
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/CrudApiControllerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Appzcoder\CrudGenerator\Commands;

use Illuminate\Console\GeneratorCommand;
use Illuminate\Support\Str;

class CrudApiControllerCommand extends GeneratorCommand
{
Expand Down Expand Up @@ -85,7 +86,7 @@ protected function buildClass($name)
$stub = $this->files->get($this->getStub());

$crudName = strtolower($this->option('crud-name'));
$crudNameSingular = str_singular($crudName);
$crudNameSingular = Str::singular($crudName);
$modelName = $this->option('model-name');
$modelNamespace = $this->option('model-namespace');
$perPage = intval($this->option('pagination'));
Expand Down
7 changes: 4 additions & 3 deletions src/Commands/CrudCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

class CrudCommand extends Command
{
Expand Down Expand Up @@ -63,12 +64,12 @@ public function __construct()
public function handle()
{
$name = $this->argument('name');
$modelName = str_singular($name);
$migrationName = str_plural(snake_case($name));
$modelName = Str::singular($name);
$migrationName = Str::plural(Str::snake($name));
$tableName = $migrationName;

$routeGroup = $this->option('route-group');
$this->routeName = ($routeGroup) ? $routeGroup . '/' . snake_case($name, '-') : snake_case($name, '-');
$this->routeName = ($routeGroup) ? $routeGroup . '/' . Str::snake($name, '-') : Str::snake($name, '-');
$perPage = intval($this->option('pagination'));

$controllerNamespace = ($this->option('controller-namespace')) ? $this->option('controller-namespace') . '\\' : '';
Expand Down
5 changes: 3 additions & 2 deletions src/Commands/CrudControllerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Appzcoder\CrudGenerator\Commands;

use Illuminate\Console\GeneratorCommand;
use Illuminate\Support\Str;

class CrudControllerCommand extends GeneratorCommand
{
Expand Down Expand Up @@ -89,14 +90,14 @@ protected function buildClass($name)

$viewPath = $this->option('view-path') ? $this->option('view-path') . '.' : '';
$crudName = strtolower($this->option('crud-name'));
$crudNameSingular = str_singular($crudName);
$crudNameSingular = Str::singular($crudName);
$modelName = $this->option('model-name');
$modelNamespace = $this->option('model-namespace');
$routeGroup = ($this->option('route-group')) ? $this->option('route-group') . '/' : '';
$routePrefix = ($this->option('route-group')) ? $this->option('route-group') : '';
$routePrefixCap = ucfirst($routePrefix);
$perPage = intval($this->option('pagination'));
$viewName = snake_case($this->option('crud-name'), '-');
$viewName = Str::snake($this->option('crud-name'), '-');
$fields = $this->option('fields');
$validations = rtrim($this->option('validations'), ';');

Expand Down
31 changes: 16 additions & 15 deletions src/Commands/CrudViewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

class CrudViewCommand extends Command
{
Expand All @@ -13,15 +14,15 @@ class CrudViewCommand extends Command
* @var string
*/
protected $signature = 'crud:view
{name : The name of the Crud.}
{--fields= : The field names for the form.}
{--view-path= : The name of the view path.}
{--route-group= : Prefix of the route group.}
{--pk=id : The name of the primary key.}
{--validations= : Validation rules for the fields.}
{--form-helper=html : Helper for the form.}
{--custom-data= : Some additional values to use in the crud.}
{--localize=no : Localize the view? yes|no.}';
{name : The name of the Crud.}
{--fields= : The field names for the form.}
{--view-path= : The name of the view path.}
{--route-group= : Prefix of the route group.}
{--pk=id : The name of the primary key.}
{--validations= : Validation rules for the fields.}
{--form-helper=html : Helper for the form.}
{--custom-data= : Some additional values to use in the crud.}
{--localize=no : Localize the view? yes|no.}';

/**
* The console command description.
Expand Down Expand Up @@ -241,14 +242,14 @@ class CrudViewCommand extends Command

/**
* Create a new command instance.
*
*/
public function __construct()
{
parent::__construct();

if (config('crudgenerator.view_columns_number')) {
$this->defaultColumnsToShow = config('crudgenerator.view_columns_number');
$this
->defaultColumnsToShow = config('crudgenerator.view_columns_number');
}

$this->delimiter = config('crudgenerator.custom_delimiter')
Expand All @@ -272,8 +273,8 @@ public function handle()
$this->crudName = strtolower($this->argument('name'));
$this->varName = lcfirst($this->argument('name'));
$this->crudNameCap = ucwords($this->crudName);
$this->crudNameSingular = str_singular($this->crudName);
$this->modelName = str_singular($this->argument('name'));
$this->crudNameSingular = Str::singular($this->crudName);
$this->modelName = Str::singular($this->argument('name'));
$this->modelNameCap = ucfirst($this->modelName);
$this->customData = $this->option('custom-data');
$this->primaryKey = $this->option('pk');
Expand All @@ -282,7 +283,7 @@ public function handle()
: $this->option('route-group');
$this->routePrefix = ($this->option('route-group')) ? $this->option('route-group') : '';
$this->routePrefixCap = ucfirst($this->routePrefix);
$this->viewName = snake_case($this->argument('name'), '-');
$this->viewName = Str::snake($this->argument('name'), '-');

$viewDirectory = config('view.paths')[0] . '/';
if ($this->option('view-path')) {
Expand Down Expand Up @@ -314,7 +315,7 @@ public function handle()

$this->formFields[$x]['name'] = trim($itemArray[0]);
$this->formFields[$x]['type'] = trim($itemArray[1]);
$this->formFields[$x]['required'] = preg_match('/' . $itemArray[0] . '/', $validations) ? true : false;
$this->formFields[$x]['required'] = preg_match('/' . $itemArray[0] . '/', $validations)? true : false;

if (($this->formFields[$x]['type'] === 'select'
|| $this->formFields[$x]['type'] === 'enum')
Expand Down

0 comments on commit b66c400

Please sign in to comment.