laravel['modules']->findOrFail($this->getModuleName()); $path = str_replace('/', '\\', config('modules.paths.generator.' . $this->argument('class'))); return (new Stub('/' . $this->argument('prefix') . $this->argument('class') . '.stub', [ 'NAMESPACE' => $this->getClassNamespace($module) . "\\" . $path, 'LOWER_NAME' => $module->getLowerName(), 'CLASS' => $this->getClass(), 'STUDLY_NAME' => Str::studly($module->getLowerName()), 'DATATABLE_COLUMNS' => $this->getColumns(), 'FORM_FIELDS' => $this->getFormFields(), 'DATABASE_FIELDS' => $this->getDatabaseFields($module), 'TRANSFORMER_FIELDS' => $this->getTransformerFields($module), ]))->render(); } public function getDestinationFilePath() { $path = $this->laravel['modules']->getModulePath($this->getModuleName()); $seederPath = $this->laravel['modules']->config('paths.generator.' . $this->argument('class')); return $path . $seederPath . '/' . $this->getFileName() . '.php'; } /** * @return string */ protected function getFileName() { if ($this->option('filename')) { return $this->option('filename'); } 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; } protected function getFormFields() { $fields = $this->option('fields'); $fields = explode(',', $fields); $str = ''; foreach ($fields as $field) { $field = explode(':', $field)[0]; $str .= '{!! Former::text(\''. $field . '\') !!} '; } return $str; } protected function getDatabaseFields($module) { $fields = $this->option('fields'); $fields = explode(',', $fields); $str = ''; foreach ($fields as $field) { $field = explode(':', $field)[0]; $str .= "'" . $module->getLowerName() . ".{$field}', "; } return $str; } protected function getTransformerFields($module) { $fields = $this->option('fields'); $fields = explode(',', $fields); $str = ''; foreach ($fields as $field) { $field = explode(':', $field)[0]; $str .= "'{$field}' => $" . $module->getLowerName() . "->$field,\n "; } return rtrim($str); } }