Skip to content

Commit d85e527

Browse files
authored
Merge pull request #145 from Laravel-Backpack/fix-crud-generated-fields-columns
Fixed CRUD Controller generated fields and columns
2 parents f7c7127 + 48ffb0c commit d85e527

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/Console/Commands/CrudControllerBackpackCommand.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Backpack\Generators\Console\Commands;
44

55
use Illuminate\Console\GeneratorCommand;
6-
use Illuminate\Support\Arr;
76
use Illuminate\Support\Str;
87

98
class CrudControllerBackpackCommand extends GeneratorCommand
@@ -162,26 +161,27 @@ protected function replaceSetFromDb(&$stub, $name)
162161
}
163162

164163
$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.' ';
165167

166168
// create an array with the needed code for defining fields
167-
$fields = Arr::except($attributes, ['id', 'created_at', 'updated_at', 'deleted_at']);
168169
$fields = collect($fields)
169170
->map(function ($field) {
170171
return "CRUD::field('$field');";
171172
})
172-
->toArray();
173+
->join($glue);
173174

174175
// create an array with the needed code for defining columns
175-
$columns = Arr::except($attributes, ['id']);
176176
$columns = collect($columns)
177177
->map(function ($column) {
178178
return "CRUD::column('$column');";
179179
})
180-
->toArray();
180+
->join($glue);
181181

182182
// replace setFromDb with actual fields and columns
183-
$stub = str_replace('CRUD::setFromDb(); // fields', implode(PHP_EOL.' ', $fields), $stub);
184-
$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);
185185

186186
return $this;
187187
}

0 commit comments

Comments
 (0)