Skip to content

Commit a99b832

Browse files
Edit command
1 parent 7f1ab0a commit a99b832

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Console/GenerateApiResourceCommand.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ protected function generateResource(Model $model): void
144144
{
145145
$class = get_class($model);
146146
$name = class_basename($class);
147-
$path = $this->dir . '/' . $name . '.php';
147+
$path = $this->dir . '/' . $name . 'Resource' . '.php';
148148

149149
if ($this->files->exists($path)) {
150150
$this->error("API Resource for $class already exists!");
@@ -165,13 +165,19 @@ protected function buildResource(string $class, string $name): string
165165
$properties = $this->properties;
166166
$fields = '';
167167

168+
$properties_length = count($properties);
169+
$count = 0;
168170
foreach ($properties as $property) {
169-
$fields .= "\t\t\t'$property' => \$this->$property,\n";
171+
if ($count < $properties_length - 1) {
172+
$fields .= "'$property' => \$this->$property,\n";
173+
} else {
174+
$fields .= "'$property' => \$this->$property";
175+
}
170176
}
171177

172178
$stub = $this->files->get($this->stub);
173179

174-
$stub = str_replace('{{ class }}', $name, $stub);
180+
$stub = str_replace('{{ class }}', $name . 'Resource', $stub);
175181
$stub = str_replace('{{ namespace }}', $this->namespace, $stub);
176182
return str_replace('{{ fields }}', $fields, $stub);
177183
}

0 commit comments

Comments
 (0)