mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
CRUD
This commit is contained in:
parent
249965df5c
commit
758e06b79b
@ -41,6 +41,19 @@ class MakeClass extends GeneratorCommand
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return array(
|
||||
array('fields', null, InputOption::VALUE_OPTIONAL, 'The model attributes.', null),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function getTemplateContents()
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
@ -51,6 +64,7 @@ class MakeClass extends GeneratorCommand
|
||||
'LOWER_NAME' => $module->getLowerName(),
|
||||
'CLASS' => $this->getClass(),
|
||||
'STUDLY_NAME' => Str::studly($module->getLowerName()),
|
||||
'COLUMNS' => $this->getColumns(),
|
||||
]))->render();
|
||||
}
|
||||
|
||||
@ -70,4 +84,23 @@ class MakeClass extends GeneratorCommand
|
||||
return studly_case($this->argument('prefix')) . studly_case($this->argument('name')) . Str::studly($this->argument('class'));
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
$fields = $this->option('fields');
|
||||
$fields = explode(',', $fields);
|
||||
$str = '';
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$field = explode(':', $field)[0];
|
||||
$str .= '[
|
||||
\''. $field . '\',
|
||||
function ($model) {
|
||||
return $model->' . $field . ';
|
||||
}
|
||||
],';
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -42,15 +42,21 @@ class MakeModule extends Command
|
||||
$fields = $this->argument('fields');
|
||||
$lower = strtolower($name);
|
||||
|
||||
// convert 'name:string,description:text' to 'name,description'
|
||||
$fillable = explode(',', $fields);
|
||||
$fillable = array_map(function($item) {
|
||||
return explode(':', $item)[0];
|
||||
}, $fillable);
|
||||
$fillable = join(',', $fillable);
|
||||
|
||||
$this->info("Creating module: {$name}");
|
||||
//$this->info("Fields: {$fields}");
|
||||
|
||||
Artisan::call('module:make', ['name' => [$name]]);
|
||||
Artisan::call('module:make-migration', ['name' => "create_{$lower}_table", '--fields' => $fields, 'module' => $name]);
|
||||
Artisan::call('module:migrate', ['module' => $name]);
|
||||
Artisan::call('module:make-model', ['model' => $name, 'module' => $name]);
|
||||
Artisan::call('module:make-model', ['model' => $name, 'module' => $name, '--fillable' => $fillable]);
|
||||
|
||||
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'datatable']);
|
||||
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'datatable', '--fields' => $fields]);
|
||||
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'repository']);
|
||||
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'policy']);
|
||||
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'auth-provider']);
|
||||
@ -70,4 +76,5 @@ class MakeModule extends Command
|
||||
['fields', InputArgument::OPTIONAL, 'The fields of the module.']
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ class $CLASS$Datatable extends EntityDatatable
|
||||
public function columns()
|
||||
{
|
||||
return [
|
||||
$COLUMNS$
|
||||
[
|
||||
'created_at',
|
||||
function ($model) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user