Skip to content

Commit 0bf3d90

Browse files
committed
Fixed CRUD Controller generated fields and columns
1 parent ad4f3a4 commit 0bf3d90

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/Console/Commands/CrudControllerBackpackCommand.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,26 +161,27 @@ protected function replaceSetFromDb(&$stub, $name)
161161
}
162162

163163
$attributes = $this->getAttributes($model);
164+
$fields = array_diff($attributes, ['id', 'created_at', 'updated_at', 'deleted_at']);
165+
$columns = array_diff($attributes, ['id']);
166+
$glue = PHP_EOL.' ';
164167

165168
// create an array with the needed code for defining fields
166-
$fields = Arr::except($attributes, ['id', 'created_at', 'updated_at', 'deleted_at']);
167169
$fields = collect($fields)
168170
->map(function ($field) {
169171
return "CRUD::field('$field');";
170172
})
171-
->toArray();
173+
->join($glue);
172174

173175
// create an array with the needed code for defining columns
174-
$columns = Arr::except($attributes, ['id']);
175176
$columns = collect($columns)
176177
->map(function ($column) {
177178
return "CRUD::column('$column');";
178179
})
179-
->toArray();
180+
->join($glue);
180181

181182
// replace setFromDb with actual fields and columns
182-
$stub = str_replace('CRUD::setFromDb(); // fields', implode(PHP_EOL.' ', $fields), $stub);
183-
$stub = str_replace('CRUD::setFromDb(); // columns', implode(PHP_EOL.' ', $columns), $stub);
183+
$stub = str_replace('CRUD::setFromDb(); // fields', $fields, $stub);
184+
$stub = str_replace('CRUD::setFromDb(); // columns', $columns, $stub);
184185

185186
return $this;
186187
}

0 commit comments

Comments
 (0)