/** * Return the namespace for generated classes * @param bool $omitLeadingSlash * @param bool $appendNamespace * @return mixed|string */ protected function getNamespace($omitLeadingSlash = false, $appendNamespace = false) { // Take namespace from option or fallback to config $namespace = $this->option('namespace') ?: $this->config->get('apigen::generators.default.namespace'); // Append a postfix to the namespace if ($appendNamespace) { $namespace .= '\\' . trim($appendNamespace, '\\'); } return $this->translator->path($namespace)->toNamespace($omitLeadingSlash); }
/** * Process the template and automatically fill in the values * @param $name * @param $fields * @return mixed */ protected function generateModelConfigFromTemplate($name, array $fields) { // Prepare fields $listFields = []; foreach ($fields as $field) { $listFields[$field['property']] = ['title' => $this->translator->translate($field['property'])->toReadableName()]; } // Prepare edit fields $editFields = []; foreach ($fields as $field) { $editFields[$field['property']] = array_merge(['title' => $this->translator->translate($field['property'])->toReadableName(), 'type' => $field['field']->getAdminType()], $field['field']->generateEditFieldsConfiguration()); } // Compile configuration template return $this->generator->compile('model_config.txt', ['MODEL_TITLE_SINGULAR' => $name->toReadableName(), 'MODEL_TITLE_PLURAL' => $name->toReadablePlural(), 'MODEL_SINGULAR' => $name->toSingularForm(), 'MODEL_ELOQUENT' => $name->toModelName(), 'MODEL_LIST_COLUMNS' => $listFields, 'MODEL_EDIT_FIELDS' => $editFields]); }