Skip to content

Commit

Permalink
Merge pull request #8 from JunaidQadirB/jq/bugfix-7
Browse files Browse the repository at this point in the history
Fixes #7 - Allow the user to choose the base directory for the views
  • Loading branch information
JunaidQadirB authored Oct 2, 2021
2 parents 5bb05cf + 5a2d03e commit 8bde12f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Console/Commands/ViewMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class ViewMakeCommand extends GeneratorCommand

private $fileName = 'index';

private string $baseViewPath;

/**
* Execute the console command.
*
Expand Down Expand Up @@ -89,14 +91,28 @@ protected function createView()
}
}

private function chooseViewPath()
{
if (!Config::has('view.paths') || (Config::has('view.paths') && count(Config::get('view.paths')) < 1)) {
return $this->viewPath();
}

if (count(Config::get('view.paths')) == 1) {
return Config::get('view.paths')[0];
}

return $this->choice('Where would you like to put your views?', Config::get('view.paths'));
}

/**
*
*/
protected function createViewDirectory()
{
$name = Str::studly(class_basename($this->argument('name')));
$viewDirSlug = Str::slug(Str::plural(str_to_words($name), 2));
$viewPath = Config::get('view.paths')[0];
$this->baseViewPath = $viewPath = $this->chooseViewPath();

$dir = $this->option('dir');

$path = $viewPath.'/'.$viewDirSlug;
Expand All @@ -122,6 +138,7 @@ protected function buildView($type, $path)
$stub = $this->replacePlaceholders($stub, $name, $path);

$target = $path.'/'.$type.'.blade.php';

if ($type == 'delete') {
$target = $path.'/modals/'.$type.'.blade.php';
}
Expand Down

0 comments on commit 8bde12f

Please sign in to comment.