/** * Replace all stub tokens with properties. * * @param $view_name * @param $table * @param $activitylog * * @return mixed|string */ protected function generateView($view_name, $table, $activitylog = false) { $properties = $this->getTableProperties($table); $uses = []; $foreign_keys = $properties['foreign_keys']; foreach ($foreign_keys as $key => $val) { $properties['foreign_keys'][$key]->referenced_class_name = Util::Table2ClassName($val->referenced_table_name); } $columns_json = []; foreach ($properties['columns'] as $key => $value) { $columns_json[$value['name']] = 'foo'; } if ($properties['softdeletes']) { $uses[] = 'SoftDeletes'; } if ($activitylog) { $uses[] = 'LogsActivity'; } $blade = new Blade($this->views, $this->cache); return $blade->view()->make($view_name, ['activitylog' => $activitylog, 'class' => $this->class, 'columns' => $properties['columns'], 'columns_json' => json_encode($columns_json), 'fillable' => Util::Array2String($properties['fillable']), 'guarded' => Util::Array2String($properties['guarded']), 'hidden' => Util::Array2String($properties['hidden']), 'foreign_keys' => $properties['foreign_keys'], 'table' => $table, 'timestamps' => $properties['timestamps'], 'uses' => implode(',', $uses), 'softdeletes' => $properties['softdeletes']])->render(); }
/** * Generate a model file from a database table. * * @param $table */ protected function process($table) { //prefix is the sub-directory within app $prefix = $this->option('dir'); $ignoreTable = $this->option("ignore"); $this->class = Util::Table2ClassName($table); $name = rtrim($this->parseName($prefix . $this->class), 's'); $path = $this->getPath($name); if ($this->option("ignoresystem")) { $ignoreSystem = "administrators,users,permissions,permission_role,roles,role_user,users,migrations,password_resets"; if (is_string($ignoreTable)) { $ignoreTable .= "," . $ignoreSystem; } else { $ignoreTable = $ignoreSystem; } } // if we have ignore tables, we need to find all the posibilites if (is_string($ignoreTable) && preg_match("/^" . $table . "|^" . $table . ",|," . $table . ",|," . $table . "\$/", $ignoreTable)) { $this->info($table . " is ignored"); return; } if ($this->files->exists($path)) { return $this->error($this->extends . ' for ' . $table . ' already exists!'); } $this->makeDirectory($path); $this->files->put($path, "<?php \n\n" . $this->generateView('model', $table, true)); $this->info($this->extends . ' for ' . $table . ' created successfully.'); }
/** * Generate a model file from a database table. * * @param $table */ protected function process($table) { //prefix is the sub-directory within app $prefix = $this->option('dir'); $ignoreTable = $this->option("ignore"); $this->class = Util::Table2ClassName($table); $name = rtrim($this->parseName($prefix . $this->class), 's'); if ($this->option("ignoresystem")) { $ignoreSystem = "users,permissions,permission_role,roles,role_user,users,migrations,password_resets"; if (is_string($ignoreTable)) { $ignoreTable .= "," . $ignoreSystem; } else { $ignoreTable = $ignoreSystem; } } // if we have ignore tables, we need to find all the posibilites if (is_string($ignoreTable) && preg_match("/^" . $table . "|^" . $table . ",|," . $table . ",|," . $table . "\$/", $ignoreTable)) { $this->info($table . " is ignored"); return; } $this_classes = ['Controller', 'Request', 'Transformer']; foreach ($this_classes as $tclass) { $path = app_path('Api/' . $tclass . 's/' . $this->class . $tclass . '.php'); if ($this->files->exists($path)) { return $this->error('Dingo API: ' . $table . $tclass . ' already exists!'); } $this->makeDirectory($path); $this->files->put($path, "<?php \n\n" . $this->generateView('api/' . strtolower($tclass), $table)); } //$new_routes = $this->blade->view()->make('api.routes', ['class' => $this->class, 'table' => $table]); $new_routes = $this->generateView('api.routes', $table); // add Dingo API methods into routes.php $translation_file = app_path('Http/routes.php'); $current = file($translation_file); array_pop($current); array_pop($current); $current[] = "\n " . $new_routes . "\n });\n});"; file_put_contents($translation_file, $current); $this->info('Dingo API: ' . $table . ' created successfully.'); }
/** * Generate a model file from a database table. * * @param $table */ protected function process($table) { //prefix is the sub-directory within app $prefix = $this->option('dir'); $ignoreTable = $this->option("ignore"); $this->class = Util::Table2ClassName($table); $name = rtrim($this->parseName($prefix . $this->class), 's'); $path = $this->getPath($name); if ($this->option("ignoresystem")) { $ignoreSystem = "users,permissions,permission_role,roles,role_user,users,migrations,password_resets"; if (is_string($ignoreTable)) { $ignoreTable .= "," . $ignoreSystem; } else { $ignoreTable = $ignoreSystem; } } // if we have ignore tables, we need to find all the posibilites if (is_string($ignoreTable) && preg_match("/^" . $table . "|^" . $table . ",|," . $table . ",|," . $table . "\$/", $ignoreTable)) { $this->info($table . " is ignored"); return; } if ($this->files->exists($path)) { return $this->error('SleepingOwl Admin for ' . $table . ' already exists!'); } $this->makeDirectory($path); $this->files->put($path, "<?php \n\n" . $this->generateView('admin', $table)); // Include new Controller into menu.php $menu = "Admin::menu(\\App\\{$this->class}::class)->label(trans('admin.{$table}'))->icon('fa-bars');\n"; file_put_contents(app_path('Admin/menu.php'), $menu, FILE_APPEND | LOCK_EX); // add string into translantions $translation_file = app_path('/../resources/lang/en/admin.php'); $current = file_get_contents($translation_file); $current = str_ireplace('];', '', $current); $current .= " '{$table}' => '" . ucwords(str_ireplace('_', ' ', $table)) . "',\n];"; file_put_contents($translation_file, $current); $this->info('SleepingOwl Admin for ' . $table . ' created successfully.'); }