44
55use Illuminate \Console \Concerns \CreatesMatchingTest ;
66use Illuminate \Console \GeneratorCommand ;
7+ use Illuminate \Foundation \Inspiring ;
78use Illuminate \Support \Str ;
89use Symfony \Component \Console \Attribute \AsCommand ;
910use Symfony \Component \Console \Input \InputOption ;
@@ -48,6 +49,10 @@ public function handle()
4849 if ($ this ->option ('markdown ' ) !== false ) {
4950 $ this ->writeMarkdownTemplate ();
5051 }
52+
53+ if ($ this ->option ('view ' ) !== false ) {
54+ $ this ->writeView ();
55+ }
5156 }
5257
5358 /**
@@ -61,13 +66,33 @@ protected function writeMarkdownTemplate()
6166 str_replace ('. ' , '/ ' , $ this ->getView ()).'.blade.php '
6267 );
6368
64- if (! $ this ->files ->isDirectory (dirname ($ path ))) {
65- $ this ->files ->makeDirectory (dirname ($ path ), 0755 , true );
66- }
69+ $ this ->files ->ensureDirectoryExists (dirname ($ path ));
6770
6871 $ this ->files ->put ($ path , file_get_contents (__DIR__ .'/stubs/markdown.stub ' ));
6972 }
7073
74+ /**
75+ * Write the Blade template for the mailable.
76+ *
77+ * @return void
78+ */
79+ protected function writeView ()
80+ {
81+ $ path = $ this ->viewPath (
82+ str_replace ('. ' , '/ ' , $ this ->getView ()) . '.blade.php '
83+ );
84+
85+ $ this ->files ->ensureDirectoryExists (dirname ($ path ));
86+
87+ $ stub = str_replace (
88+ '{{ quote }} ' ,
89+ Inspiring::quotes ()->random (),
90+ file_get_contents (__DIR__ . '/stubs/view.stub ' )
91+ );
92+
93+ $ this ->files ->put ($ path , $ stub );
94+ }
95+
7196 /**
7297 * Build the class with the given name.
7398 *
@@ -82,7 +107,7 @@ protected function buildClass($name)
82107 parent ::buildClass ($ name )
83108 );
84109
85- if ($ this ->option ('markdown ' ) !== false ) {
110+ if ($ this ->option ('markdown ' ) !== false || $ this -> option ( ' view ' ) !== false ) {
86111 $ class = str_replace (['DummyView ' , '{{ view }} ' ], $ this ->getView (), $ class );
87112 }
88113
@@ -96,7 +121,7 @@ protected function buildClass($name)
96121 */
97122 protected function getView ()
98123 {
99- $ view = $ this ->option ('markdown ' );
124+ $ view = $ this ->option ('markdown ' ) ?: $ this -> option ( ' view ' ) ;
100125
101126 if (! $ view ) {
102127 $ name = str_replace ('\\' , '/ ' , $ this ->argument ('name ' ));
@@ -116,10 +141,15 @@ protected function getView()
116141 */
117142 protected function getStub ()
118143 {
119- return $ this ->resolveStubPath (
120- $ this ->option ('markdown ' ) !== false
121- ? '/stubs/markdown-mail.stub '
122- : '/stubs/mail.stub ' );
144+ if ($ this ->option ('markdown ' ) !== false ) {
145+ return $ this ->resolveStubPath ('/stubs/markdown-mail.stub ' );
146+ }
147+
148+ if ($ this ->option ('view ' ) !== false ) {
149+ return $ this ->resolveStubPath ('/stubs/view-mail.stub ' );
150+ }
151+
152+ return $ this ->resolveStubPath ('/stubs/mail.stub ' );
123153 }
124154
125155 /**
@@ -156,6 +186,7 @@ protected function getOptions()
156186 return [
157187 ['force ' , 'f ' , InputOption::VALUE_NONE , 'Create the class even if the mailable already exists ' ],
158188 ['markdown ' , 'm ' , InputOption::VALUE_OPTIONAL , 'Create a new Markdown template for the mailable ' , false ],
189+ ['view ' , null , InputOption::VALUE_OPTIONAL , 'Create a new Blade template for the mailable ' , false ],
159190 ];
160191 }
161192}
0 commit comments