From 710445a8d00155b7706d776eba5e55fe3429fec3 Mon Sep 17 00:00:00 2001 From: BJ Hansen Date: Tue, 6 Aug 2024 09:16:00 -0500 Subject: [PATCH] Bug fix when creating a resourceful view bundle --- src/MakeView.php | 50 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/src/MakeView.php b/src/MakeView.php index 46a0cc5..59a9b0a 100644 --- a/src/MakeView.php +++ b/src/MakeView.php @@ -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; + } } }