|
3 | 3 | namespace Backpack\Generators\Console\Commands; |
4 | 4 |
|
5 | 5 | use Illuminate\Console\GeneratorCommand; |
6 | | -use Illuminate\Support\Arr; |
7 | 6 | use Illuminate\Support\Str; |
8 | 7 |
|
9 | 8 | class CrudControllerBackpackCommand extends GeneratorCommand |
@@ -162,26 +161,27 @@ protected function replaceSetFromDb(&$stub, $name) |
162 | 161 | } |
163 | 162 |
|
164 | 163 | $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.' '; |
165 | 167 |
|
166 | 168 | // create an array with the needed code for defining fields |
167 | | - $fields = Arr::except($attributes, ['id', 'created_at', 'updated_at', 'deleted_at']); |
168 | 169 | $fields = collect($fields) |
169 | 170 | ->map(function ($field) { |
170 | 171 | return "CRUD::field('$field');"; |
171 | 172 | }) |
172 | | - ->toArray(); |
| 173 | + ->join($glue); |
173 | 174 |
|
174 | 175 | // create an array with the needed code for defining columns |
175 | | - $columns = Arr::except($attributes, ['id']); |
176 | 176 | $columns = collect($columns) |
177 | 177 | ->map(function ($column) { |
178 | 178 | return "CRUD::column('$column');"; |
179 | 179 | }) |
180 | | - ->toArray(); |
| 180 | + ->join($glue); |
181 | 181 |
|
182 | 182 | // 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); |
185 | 185 |
|
186 | 186 | return $this; |
187 | 187 | } |
|
0 commit comments