Skip to content

Commit

Permalink
Bug fix when creating a resourceful view bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminhansen committed Aug 6, 2024
1 parent eb14ec0 commit 710445a
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions src/MakeView.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,50 @@ public function handle()
}
}
} else {
// we are dealing with a single/top-level blade file
$blade_file = "{$viewname}.blade.php";
$full_view_path = "{$view_path}/{$blade_file}";
if(!file_exists($full_view_path)) {
touch($full_view_path);
} else {
$this->error("View [$viewname] already exists!");
if($resourceful) {
// we should create a view folder and resourceful view files inside (index, create, show, edit)
$resource_files = ['index.blade.php', 'create.blade.php', 'show.blade.php', 'edit.blade.php'];

$view_path .= "/{$viewname}";

if(!file_exists($view_path)) {
mkdir($view_path);
}

foreach($resource_files as $file) {
$file_view_path = "{$view_path}/{$file}";
if(!file_exists($file_view_path)) {
touch($file_view_path);
} else {
$this->error("View file [$file_view_path] already exists!");
return;
}

if($extends) {
$content = file_get_contents(__DIR__."/shells/extends.txt");
$content = str_replace("{{BASE_VIEW}}", $extends, $content);

file_put_contents($file_view_path, $content);
}
}

if($extends) {
$this->info("Resourceful child views created at [$viewname]");
} else {
$this->info("Resourceful views created at [$viewname]");
}

return;
} else {
// we are dealing with a single/top-level blade file
$blade_file = "{$viewname}.blade.php";
$full_view_path = "{$view_path}/{$blade_file}";
if(!file_exists($full_view_path)) {
touch($full_view_path);
} else {
$this->error("View [$viewname] already exists!");
return;
}
}
}

Expand Down

0 comments on commit 710445a

Please sign in to comment.