Skip to content

Commit 5000d7f

Browse files
committed
View name is now underscored snake case
1 parent d1e116e commit 5000d7f

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/Console/Commands/PageBackpackCommand.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,26 @@ class PageBackpackCommand extends GeneratorCommand
4848
*/
4949
public function handle()
5050
{
51-
$filePath = Str::of($this->getNameInput())
51+
$input = Str::of($this->getNameInput())
5252
->replace('\\', '/')
5353
->replace('.', '/')
54-
->trim('/')
5554
->start('/')
56-
->prepend($this->option('view-path'));
55+
->prepend($this->option('view-path'))
56+
->replace('//', '/')
57+
->trim('/');
5758

58-
$name = $filePath->afterLast('/');
59-
$path = $filePath->beforeLast('/');
59+
$name = $input->afterLast('/')->replace('-', '_')->snake();
60+
$path = $input->beforeLast('/');
61+
$filePath = "$path/$name";
6062
$fullpath = $this->getPath($filePath);
6163
$layout = $this->option('layout');
6264

63-
$this->infoBlock("Creating {$name->title()} page");
65+
$this->infoBlock("Creating {$name->replace('_', ' ')->title()} page");
6466

6567
$this->progressBlock("Creating view <fg=blue>resources/views/${filePath}.php</>");
6668

6769
// check if the file already exists
68-
if ((! $this->hasOption('force') || ! $this->option('force')) && $this->alreadyExists($fullpath)) {
70+
if ((! $this->hasOption('force') || ! $this->option('force')) && $this->alreadyExists($filePath)) {
6971
$this->closeProgressBlock('Already existed', 'yellow');
7072

7173
return false;

src/Console/Commands/PageControllerBackpackCommand.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,25 @@ class PageControllerBackpackCommand extends GeneratorCommand
4747
public function handle()
4848
{
4949
$name = $this->getNameInput();
50-
$this->progressBlock("Creating controller <fg=blue>${name}Controller</>");
50+
$class = $this->qualifyClass($name);
51+
$fullPath = $this->getPath($class);
52+
$path = Str::of($fullPath)->after(base_path())->trim('\\/');
5153

52-
if ($this->isReservedName($this->getNameInput())) {
54+
$this->progressBlock("Creating controller <fg=blue>{$path}</>");
55+
56+
if ($this->isReservedName($name)) {
5357
$this->errorProgressBlock();
5458
$this->note("The name '$name' is reserved by PHP.", 'red');
5559

5660
return false;
5761
}
5862

59-
$name = $this->qualifyClass($this->getNameInput());
60-
61-
$path = $this->getPath($name);
62-
6363
// Next, We will check to see if the class already exists. If it does, we don't want
6464
// to create the class and overwrite the user's code. So, we will bail out so the
6565
// code is untouched. Otherwise, we will continue generating this class' files.
6666
if ((! $this->hasOption('force') ||
6767
! $this->option('force')) &&
68-
$this->alreadyExists($this->getNameInput())) {
68+
$this->alreadyExists($class)) {
6969
$this->closeProgressBlock('Already existed', 'yellow');
7070

7171
return false;
@@ -74,9 +74,9 @@ public function handle()
7474
// Next, we will generate the path to the location where this class' file should get
7575
// written. Then, we will build the class and make the proper replacements on the
7676
// stub files so that it gets the correctly formatted namespace and class name.
77-
$this->makeDirectory($path);
77+
$this->makeDirectory($fullPath);
7878

79-
$this->files->put($path, $this->sortImports($this->buildClass($name)));
79+
$this->files->put($fullPath, $this->sortImports($this->buildClass($class)));
8080

8181
$this->closeProgressBlock();
8282
}

0 commit comments

Comments
 (0)