/** * Build migration fields * @return string */ private function buildFields() { $migrationTypes = FieldsDescriber::migration(); $used = []; $fields = '$table->increments("id");' . "\r\n"; foreach ($this->fields as $field) { // Check if there is no duplication for radio and checkbox if (!in_array($field->title, $used)) { // Generate our migration line $migrationLine = str_replace(['$FIELDNAME$', '$STATE$', '$RELATIONSHIP$'], [$field->title, $field->default == 'true' ? 1 : 0, $field->relationship_name], $migrationTypes[$field->type]); $fields .= ' '; // Add formatting space to the migration $fields .= '$table->' . $migrationLine . ";\r\n"; if ($field->type == 'relationship') { $used[$field->relationship_name] = $field->relationship_name; } else { $used[$field->title] = $field->title; } } } $fields .= ' '; // Add formatting space to the migration $fields .= '$table->timestamps();'; if ($this->soft == 1) { $fields .= "\r\n"; $fields .= ' '; // Add formatting space to the migration $fields .= '$table->softDeletes();'; } return $fields; }
/** * Show new crud creation page * @return \Illuminate\View\View */ public function create() { $fieldTypes = FieldsDescriber::types(); $fieldValidation = FieldsDescriber::validation(); $defaultValuesCbox = FieldsDescriber::default_cbox(); $crudsSelect = Crud::lists('title', 'id'); // Get columns for relationship $models = []; foreach (Crud::all() as $crud) { // We are having a default User model if ($crud->title == 'User' && $crud->is_crud == 0) { $tableName = 'users'; } else { $tableName = strtolower($crud->name); } $models[$crud->id] = Schema::getColumnListing($tableName); } return view("qa::cruds.create", compact('fieldTypes', 'fieldValidation', 'defaultValuesCbox', 'crudsSelect', 'models')); }