Skip to content

Commit d4a95f0

Browse files
committed
Fixes a bug with where generating create/edit views
1 parent afbf7e4 commit d4a95f0

File tree

4 files changed

+32
-34
lines changed

4 files changed

+32
-34
lines changed

src/Commands/CreateControllerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function handle()
141141
->replaceRelationCollections($stub, $this->getRequiredRelationCollections($fields))
142142
->replaceOnStoreAction($stub, $this->getOnStoreAction($fields))
143143
->replaceOnUpdateAction($stub, $this->getOnUpdateAction($fields))
144-
->replaceAppName($stub, $this->getAppName())
144+
->replaceAppName($stub, Helpers::getAppName())
145145
->replaceControllerName($stub, $input->controllerName)
146146
->replaceDataVariable($stub, 'data')
147147
->replaceRequestName($stub, $requestName)

src/Support/Helpers.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ public static function eliminateDupilcates($subject, $eliminate = "\\")
4848
return $subject;
4949
}
5050

51+
/**
52+
* Gets the app folder name,
53+
*
54+
* @return string
55+
*/
56+
public static function getAppName()
57+
{
58+
return rtrim(self::getAppNamespace(), '\\');
59+
}
60+
5161
/**
5262
* Gets the model full path.
5363
*

src/Traits/CommonCommand.php

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ protected function getIndent($stub, $template)
191191
*
192192
* @return string
193193
*/
194-
protected function Indent($multiplier)
194+
protected function indent($multiplier)
195195
{
196196
if ($multiplier < 1) {
197197
return '';
@@ -217,6 +217,8 @@ public function options()
217217
/**
218218
* Override Laravel's option method
219219
*
220+
* @param string $key
221+
*
220222
* @return string
221223
*/
222224
public function generatorOption($key)
@@ -237,17 +239,16 @@ public function generatorOption($key)
237239
*
238240
* @param string $stub
239241
* @param string $viewDirectory
242+
* @param string $routesPrefix
240243
* @param array $views
241244
*
242245
* @return $this
243246
*/
244247
protected function replaceViewNames(&$stub, $viewDirectory, $routesPrefix, array $views = null)
245248
{
246-
$views = empty($views) ? $this->views : $views;
247-
248-
foreach ($views as $view) {
249+
foreach (($views ?: $this->views) as $view) {
249250
$viewName = $this->getDotNotationName($viewDirectory, $routesPrefix, $view);
250-
$viewTemplate = $this->getViewName($view);
251+
$viewTemplate = $this->getViewTemplateName($view);
251252
$stub = $this->strReplace($viewTemplate, $viewName, $stub);
252253
}
253254

@@ -302,9 +303,7 @@ protected function getStubByName($name, $template = null)
302303
*/
303304
protected function replaceRouteNames(&$stub, $modelName, $routesPrefix, array $actions = null)
304305
{
305-
$actions = empty($actions) ? $this->actions : $actions;
306-
307-
foreach ($actions as $action) {
306+
foreach (($actions ?: $this->actions) as $action) {
308307
$routeName = $this->getDotNotationName($modelName, $routesPrefix, $action);
309308
$routeTemplate = $this->getRouteName($action);
310309
$stub = $this->strReplace($routeTemplate, $routeName, $stub);
@@ -326,13 +325,13 @@ protected function getRouteName($action)
326325
}
327326

328327
/**
329-
* Gets a view name
328+
* Gets a view template name
330329
*
331-
* @param string $action
330+
* @param string $view
332331
*
333332
* @return string
334333
*/
335-
protected function getViewName($view)
334+
protected function getViewTemplateName($view)
336335
{
337336
return sprintf('%s_view_name', $view);
338337
}
@@ -350,28 +349,6 @@ protected function getStubContent($name, $template = null)
350349
return $this->getFileContent($this->getStubByName($name, $template));
351350
}
352351

353-
/**
354-
* Gets the app namespace.
355-
*
356-
* @return string
357-
*/
358-
/*
359-
protected function getAppNamespace()
360-
{
361-
return Container::getInstance()->getNamespace();
362-
}
363-
*/
364-
365-
/**
366-
* Gets the app folder name,
367-
*
368-
* @return string
369-
*/
370-
protected function getAppName()
371-
{
372-
return rtrim(Helpers::getAppNamespace(), '\\');
373-
}
374-
375352
/**
376353
* Determine if a file already exists after checking for a --force option in the command.
377354
*

src/Traits/GeneratorReplacers.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ protected function replaceStandardLabels(&$stub, array $items)
5757
}
5858
return $this;
5959
}
60+
6061
/**
6162
* Gets the
6263
*
@@ -68,6 +69,7 @@ protected function modelNamePlainEnglish($modelName)
6869
{
6970
return str_replace('_', ' ', snake_case($modelName));
7071
}
72+
7173
/**
7274
* Replace the controller_name fo the given stub.
7375
*
@@ -81,6 +83,7 @@ protected function replaceControllerName(&$stub, $name)
8183
$stub = $this->strReplace('controller_name', $name, $stub);
8284
return $this;
8385
}
86+
8487
/**
8588
* It Replaces the primary key in a giving stub
8689
*
@@ -93,6 +96,7 @@ protected function replacePrimaryKey(&$stub, $primaryKey)
9396
{
9497
return $this->replaceTemplate('primary_key', $primaryKey, $stub);
9598
}
99+
96100
/**
97101
* Replace the app_name fo the given stub.
98102
*
@@ -105,6 +109,7 @@ protected function replaceAppName(&$stub, $name)
105109
{
106110
return $this->replaceTemplate('app_name', $name, $stub);
107111
}
112+
108113
/**
109114
* Replace the namespace fo the given stub.
110115
*
@@ -117,6 +122,7 @@ protected function replaceNamespace(&$stub, $namespace)
117122
{
118123
return $this->replaceTemplate('namespace', $namespace, $stub);
119124
}
125+
120126
/**
121127
* Replace the validation rules for the given stub.
122128
*
@@ -129,6 +135,7 @@ protected function replaceValidationRules(&$stub, $rules)
129135
{
130136
return $this->replaceTemplate('validation_rules', $rules, $stub);
131137
}
138+
132139
/**
133140
* Replaces the field's name for the given stub.
134141
*
@@ -141,6 +148,7 @@ protected function replaceFieldName(&$stub, $name)
141148
{
142149
return $this->replaceTemplate('field_name', $name, $stub);
143150
}
151+
144152
/**
145153
* Gets a model.
146154
*
@@ -152,6 +160,7 @@ protected function getModelCapName($name)
152160
{
153161
return ucwords($name);
154162
}
163+
155164
/**
156165
* Gets a model name.
157166
*
@@ -163,6 +172,7 @@ protected function getModelName($name)
163172
{
164173
return snake_case($name);
165174
}
175+
166176
/**
167177
* Gets a model name in a plural formal.
168178
*
@@ -174,6 +184,7 @@ protected function getModelPluralName($name)
174184
{
175185
return Str::plural(strtolower($name));
176186
}
187+
177188
/**
178189
* Gets a model name in a plural formal "Caps".
179190
*

0 commit comments

Comments
 (0)