@@ -23,7 +23,8 @@ class PageBackpackCommand extends GeneratorCommand
2323 */
2424 protected $ signature = 'backpack:page {name}
2525 {--view-path=admin : Path for the view, after resources/views/}
26- {--layout= : Base layout for the page} ' ;
26+ {--route= : Path for the route, after admin/}
27+ {--layout=blank : Base layout for the page} ' ;
2728
2829 /**
2930 * The console command description.
@@ -53,16 +54,20 @@ public function handle()
5354 ->replace ('. ' , '/ ' )
5455 ->start ('/ ' )
5556 ->prepend ($ this ->option ('view-path ' ))
57+ ->replace ('\\' , '/ ' )
5658 ->replace ('// ' , '/ ' )
5759 ->trim ('/ ' );
5860
59- $ name = $ input ->afterLast ('/ ' )->replace ('- ' , '_ ' )->snake ();
60- $ path = $ input ->beforeLast ('/ ' );
61- $ filePath = "$ path/ $ name " ;
62- $ fullpath = $ this ->getPath ($ filePath );
63- $ layout = $ this ->option ('layout ' );
61+ $ name = $ input ->afterLast ('/ ' );
62+ $ nameSnake = $ name ->snake ();
63+ $ nameTitle = $ nameSnake ->replace ('_ ' , ' ' )->replace ('- ' , ' ' )->title ();
64+ $ path = $ input ->beforeLast ($ name )->trim ('/ \\' );
65+ $ filePath = Str::of ("$ path/ $ name " )->trim ('/ \\' );
66+ $ fullPath = $ this ->getPath ($ filePath );
67+ $ layout = Str::of ($ this ->option ('layout ' ))->replace ('\\' , '/ ' )->replace ('/ ' , '. ' );
68+ $ route = Str::of ($ this ->option ('route ' ) ?? $ nameSnake )->replace ('\\' , '/ ' )->trim ('/ ' );
6469
65- $ this ->infoBlock ("Creating {$ name -> replace ( ' _ ' , ' ' )-> title () } page " );
70+ $ this ->infoBlock ("Creating {$ nameTitle } page " );
6671
6772 $ this ->progressBlock ("Creating view <fg=blue>resources/views/ $ {filePath}.blade.php</> " );
6873
@@ -73,40 +78,37 @@ public function handle()
7378 return false ;
7479 }
7580
76- $ this ->makeDirectory ($ fullpath );
81+ $ this ->makeDirectory ($ fullPath );
7782
7883 // create page view
7984 $ stub = $ this ->buildClass ($ filePath );
8085 $ stub = str_replace ('layout ' , $ layout , $ stub );
81- $ stub = str_replace ('Dummy Name ' , $ name -> replace ( ' _ ' , ' ' )-> title () , $ stub );
82- $ this ->files ->put ($ fullpath , $ stub );
86+ $ stub = str_replace ('Dummy Name ' , $ nameTitle , $ stub );
87+ $ this ->files ->put ($ fullPath , $ stub );
8388
8489 $ this ->closeProgressBlock ();
8590
86- // Clean up name
87- $ name = $ name ->replace ('_ ' , ' ' )->replace ('- ' , ' ' )->title ();
88-
8991 // create controller
9092 $ this ->call ('backpack:page-controller ' , [
91- 'name ' => $ name ,
93+ 'name ' => $ nameTitle ,
9294 '--view-path ' => $ path ,
9395 ]);
9496
9597 // create route
9698 $ this ->call ('backpack:add-custom-route ' , [
97- 'code ' => "Route::get(' {$ name -> kebab () }', ' {$ name ->studly ()}Controller@index')->name('page. {$ name -> kebab () }.index'); " ,
99+ 'code ' => "Route::get(' {$ route }', ' {$ nameTitle ->studly ()}Controller@index')->name('page. {$ nameSnake }.index'); " ,
98100 ]);
99101
100102 // create the sidebar item
101103 $ this ->call ('backpack:add-sidebar-content ' , [
102- 'code ' => "<li class= \"nav-item \"><a class= \"nav-link \" href= \"{{ backpack_url(' {$ name -> kebab () }') }} \"><i class= \"nav-icon la la-question \"></i> {$ name }</a></li> " ,
104+ 'code ' => "<li class= \"nav-item \"><a class= \"nav-link \" href= \"{{ backpack_url(' {$ route }') }} \"><i class= \"nav-icon la la-question \"></i> {$ nameTitle }</a></li> " ,
103105 ]);
104106
105- $ url = Str:: of ( config ( ' app.url ' ))-> finish ( ' / ' )-> append ( " admin/ { $ name -> kebab ()}" );
107+ $ url = backpack_url ( $ route );
106108
107109 $ this ->newLine ();
108- $ this ->note ("Page {$ name } created. " );
109- $ this ->note ("Go to <fg=blue> $ url</> to access your new page. " );
110+ $ this ->note ("Page {$ nameTitle } created. " );
111+ $ this ->note ("Go to <fg=blue> { $ url} </> to access your new page. " );
110112 $ this ->newLine ();
111113 }
112114
0 commit comments