app/Console/Kernel.php
and add BenjaminHansen\LaravelMak
## Usage
-php artisan make:view view.name --extends=layouts.app --bootstrap=bs-version --empty --resourceful
+php artisan make:view view.name --extends=layouts.app --uses=bootstrap4/bootstrap5 --empty --resourceful --suffix=something.php
- resourceful
used to create a view directory from view.name
and then resourceful view files index.blade.php
, create.blade.php
, show.blade.php
, and edit.blade.php
@@ -27,3 +27,5 @@ Open app/Console/Kernel.php
and add BenjaminHansen\LaravelMak
- empty
option is optional. Creates an empty view file with no layout extension.
- When using the empty
option all other options are ignored.
+
+- suffix
is optional if you want to override the default blade.php file suffix with something else.
diff --git a/src/MakeView.php b/src/MakeView.php
index 59a9b0a..8a3ecfe 100644
--- a/src/MakeView.php
+++ b/src/MakeView.php
@@ -6,21 +6,19 @@
class MakeView extends Command
{
- protected $deprecated_bootstrap_versions = ['v3'];
-
/**
* The name and signature of the console command.
*
* @var string
*/
- protected $signature = "make:view {viewname} {--e|extends=} {--bs|bootstrap=} {--E|empty} {--r|resourceful}";
+ protected $signature = "make:view {viewname} {--extends=} {--uses=} {--empty} {--resourceful} {--suffix=}";
/**
* The console command description.
*
* @var string
*/
- protected $description = 'Make a new Blade View with configurable options';
+ protected $description = 'Make a new Blade View with configurable options.';
/**
* Create a new command instance.
@@ -41,19 +39,20 @@ public function handle()
{
$viewname = $this->argument('viewname');
$extends = $this->option('extends') ?? env('BASE_VIEW');
- $bootstrap = $this->option('bootstrap');
+ $uses = $this->option('uses');
$empty = $this->option('empty');
$resourceful = $this->option('resourceful');
+ $suffix = $this->option('suffix') ?? 'blade.php';
$view_path = base_path('resources/views');
// handle the actual file creation for the given blade view
if(str_contains($viewname, '.')) {
+ $parts = explode(".", $viewname);
+
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'];
-
- $parts = explode(".", $viewname);
+ $resource_files = ["index.{$suffix}", "create.{$suffix}", "show.{$suffix}", "edit.{$suffix}"];
foreach($parts as $folder) {
$folder = strtolower($folder); // lowercase all folder names
@@ -91,12 +90,9 @@ public function handle()
return;
} else {
- // we are dealing with at least one folder (the string includes a ".")
- $parts = explode(".", $viewname);
-
// get the last element of the array, which is our blade view file
$blade_template = strtolower(end($parts));
- $blade_file = "{$blade_template}.blade.php";
+ $blade_file = "{$blade_template}.{$suffix}";
// remove the last element from the array since it is our filename
array_pop($parts);
@@ -125,7 +121,7 @@ public function handle()
} else {
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'];
+ $resource_files = ["index.{$suffix}", "create.{$suffix}", "show.{$suffix}", "edit.{$suffix}"];
$view_path .= "/{$viewname}";
@@ -159,7 +155,7 @@ public function handle()
return;
} else {
// we are dealing with a single/top-level blade file
- $blade_file = "{$viewname}.blade.php";
+ $blade_file = "{$viewname}.{$suffix}";
$full_view_path = "{$view_path}/{$blade_file}";
if(!file_exists($full_view_path)) {
touch($full_view_path);
@@ -176,20 +172,15 @@ public function handle()
return;
}
- // handle any extends or bootstrap logic
+ // handle any extends or uses logic
if($viewname == $extends) {
// we are creating a layout/masterpage, get the requested template and then bail out
- $html = match($bootstrap) {
- "v3" => file_get_contents(__DIR__."/shells/bootstrap3.txt"),
- "v4" => file_get_contents(__DIR__."/shells/bootstrap4.txt"),
- "v5" => file_get_contents(__DIR__."/shells/bootstrap5.txt"),
+ $html = match($uses) {
+ "bootstrap4" => file_get_contents(__DIR__."/shells/bootstrap4.txt"),
+ "bootstrap5" => file_get_contents(__DIR__."/shells/bootstrap5.txt"),
default => file_get_contents(__DIR__."/shells/raw.txt")
};
- if($bootstrap && in_array($bootstrap, $this->deprecated_bootstrap_versions)) {
- $this->warn("Bootstrap {$bootstrap} is deprecated, and will be removed soon. Please switch to a newer version as soon as possible.");
- }
-
file_put_contents($full_view_path, $html);
$this->info("Layout view [$viewname] created");
diff --git a/src/shells/bootstrap3.txt b/src/shells/bootstrap3.txt
deleted file mode 100644
index 0792d62..0000000
--- a/src/shells/bootstrap3.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
- This is your blank layout/masterpage.
-
-
-
-
-
- This is your blank layout/masterpage with Bootstrap v3 included.
-
-