Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wn/lumen-generators",
"description": "A collection of generators for Lumen and Laravel 5.",
"name": "wn/lumen-generators-6",
"description": "A collection of generators for Lumen and Laravel 6.",
"keywords": ["lumen", "laravel", "rest", "api", "generators"],
"license": "MIT",
"authors": [
Expand All @@ -11,8 +11,8 @@
],
"require": {
"php": ">=5.5.0",
"illuminate/console": "^5.1",
"illuminate/filesystem": "^5.1",
"illuminate/console": "^6.0",
"illuminate/filesystem": "^6.0",
"fzaninotto/faker": "^1.5"
},
"autoload": {
Expand Down
610 changes: 415 additions & 195 deletions composer.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Commands/ControllerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function handle()
$name = explode("\\", $model);
$name = $name[count($name) - 1];
}
$controller = ucwords(str_plural($name)) . 'Controller';
$controller = ucwords(\Illuminate\Support\Str::plural($name)) . 'Controller';
$content = $this->getTemplate('controller')
->with([
'name' => $controller,
Expand All @@ -36,7 +36,7 @@ public function handle()
$this->save($content, "./app/Http/Controllers/{$controller}.php", "{$controller}");
if(! $this->option('no-routes')){
$options = [
'resource' => snake_case($name, '-'),
'resource' => \Illuminate\Support\Str::snake($name, '-'),
'--controller' => $controller,
];

Expand Down
6 changes: 3 additions & 3 deletions src/Commands/MigrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class MigrationCommand extends BaseCommand {
public function handle()
{
$table = $this->argument('table');
$name = 'Create' . ucwords(camel_case($table));
$snakeName = snake_case($name);
$name = 'Create' . ucwords(\Illuminate\Support\Str::camel($table));
$snakeName = \Illuminate\Support\Str::snake($name);

$content = $this->getTemplate('migration')
->with([
Expand Down Expand Up @@ -129,7 +129,7 @@ protected function getConstraintDeclaration($key)
$key['column'] = 'id';
}
if(! $key['table']){
$key['table'] = str_plural(substr($key['name'], 0, count($key['name']) - 4));
$key['table'] = \Illuminate\Support\Str::plural(substr($key['name'], 0, strlen($key['name']) - 4));
}

$constraint = $this->getTemplate('migration/foreign-key')
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ModelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function getRelationsByType($type, $option, $withTimestamps = false)
foreach ($items as $item) {
$item['type'] = $type;
if(! $item['model']){
$item['model'] = $this->getNamespace() . '\\' . ucwords(str_singular($item['name']));
$item['model'] = $this->getNamespace() . '\\' . ucwords(\Illuminate\Support\Str::singular($item['name']));
} else if(strpos($item['model'], '\\') === false ){
$item['model'] = $this->getNamespace() . '\\' . $item['model'];
}
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/PivotSeederCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function handle()
protected function getResources()
{
$resources = array_map(function($arg) {
return snake_case(str_singular($this->argument($arg)));
return \Illuminate\Support\Str::snake(\Illuminate\Support\Str::singular($this->argument($arg)));
}, ['model1', 'model2']);

sort($resources);
Expand All @@ -46,13 +46,13 @@ protected function getResources()

protected function getSeederName($resources) {
$resources = array_map(function($resource){
return ucwords(camel_case($resource));
return ucwords(\Illuminate\Support\Str::camel($resource));
}, $resources);
return implode('', $resources) . 'TableSeeder';
}

protected function getTableNames($resources) {
return array_map('str_plural', $resources);
return array_map('\Illuminate\Support\Str::plural', $resources);
}

}
2 changes: 1 addition & 1 deletion src/Commands/PivotTableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function handle()
protected function parseTables()
{
$this->tables = array_map(function($arg) {
return snake_case(str_singular($this->argument($arg)));
return \Illuminate\Support\Str::snake(\Illuminate\Support\Str::singular($this->argument($arg)));
}, ['model1', 'model2']);

sort($this->tables);
Expand Down
7 changes: 4 additions & 3 deletions src/Commands/ResourceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


use InvalidArgumentException;
use Illuminate\Support\Str;

class ResourceCommand extends BaseCommand {

Expand Down Expand Up @@ -29,8 +30,8 @@ public function handle()
$this->parseFields();

$resourceName = $this->argument('name');
$modelName = ucwords(camel_case($resourceName));
$tableName = str_plural($resourceName);
$modelName = ucwords(Str::camel($resourceName));
$tableName = Str::plural($resourceName);

// generating the model
$this->call('wn:model', [
Expand Down Expand Up @@ -162,7 +163,7 @@ protected function foreignKeys()
if($index) {
$name = substr($name, $index + 1);
}
return snake_case(str_singular($name)) . '_id';
return Str::snake(Str::singular($name)) . '_id';
}, $relations);
}

Expand Down
17 changes: 9 additions & 8 deletions src/Commands/ResourcesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use InvalidArgumentException;
use Symfony\Component\Yaml\Yaml;
use Illuminate\Support\Str;


class ResourcesCommand extends BaseCommand {
Expand All @@ -26,8 +27,8 @@ public function handle()
$modelIndex = 0;
foreach ($content as $model => $i){
$i = $this->getResourceParams($model, $i);
$migrationName = 'Create' . ucwords(str_plural($i['name']));
$migrationFile = date('Y_m_d_His') . '-' . str_pad($modelIndex , 3, 0, STR_PAD_LEFT) . '_' . snake_case($migrationName) . '_table';
$migrationName = 'Create' . ucwords(Str::plural($i['name']));
$migrationFile = date('Y_m_d_His') . '-' . str_pad($modelIndex , 3, 0, STR_PAD_LEFT) . '_' . Str::snake($migrationName) . '_table';


$options = [
Expand Down Expand Up @@ -76,7 +77,7 @@ public function handle()

protected function getResourceParams($modelName, $i)
{
$i['name'] = snake_case($modelName);
$i['name'] = Str::snake($modelName);

foreach(['hasMany', 'hasOne', 'add', 'belongsTo', 'belongsToMany'] as $relation){
if(isset($i[$relation])){
Expand All @@ -92,13 +93,13 @@ protected function getResourceParams($modelName, $i)
$table = '';

if(! $relation['model']){
$table = snake_case($relation['name']);
$table = Str::snake($relation['name']);
} else {
$names = array_reverse(explode("\\", $relation['model']));
$table = snake_case($names[0]);
$table = Str::snake($names[0]);
}

$tables = [ str_singular($table), $i['name'] ];
$tables = [ Str::singular($table), $i['name'] ];
sort($tables);
$this->pivotTables[] = $tables;
}
Expand All @@ -117,10 +118,10 @@ protected function getResourceParams($modelName, $i)
protected function serializeField($field)
{
$name = $field['name'];
$schema = $this->convertArray(str_replace(':', '.', $field['schema']), ' ', ':');
$schema = $this->convertArray(Str::replace(':', '.', $field['schema']), ' ', ':');
$rules = (isset($field['rules'])) ? trim($field['rules']) : '';
// Replace space by comma
$rules = str_replace(' ', ',', $rules);
$rules = Str::replace(' ', ',', $rules);

$tags = $this->convertArray($field['tags'], ' ', ',');

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/RouteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function getController()
{
$controller = $this->option('controller');
if(! $controller){
$controller = ucwords(str_plural(camel_case($this->argument('resource')))) . 'Controller';
$controller = ucwords(\Illuminate\Support\Str::plural(\Illuminate\Support\Str::camel($this->argument('resource')))) . 'Controller';
}
return $controller;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/SeederCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function handle()
protected function getSeederName($name)
{
$name = explode("\\", $name);
$name = ucwords(str_plural($name[count($name) - 1]));
$name = ucwords(\Illuminate\Support\Str::plural($name[count($name) - 1]));
$name = $name . 'TableSeeder';
return $name;
}
Expand Down