4
4
5
5
use Illuminate \Console \Concerns \CreatesMatchingTest ;
6
6
use Illuminate \Console \GeneratorCommand ;
7
+ use Illuminate \Foundation \Inspiring ;
7
8
use Illuminate \Support \Str ;
8
9
use Symfony \Component \Console \Attribute \AsCommand ;
9
10
use Symfony \Component \Console \Input \InputOption ;
@@ -48,6 +49,10 @@ public function handle()
48
49
if ($ this ->option ('markdown ' ) !== false ) {
49
50
$ this ->writeMarkdownTemplate ();
50
51
}
52
+
53
+ if ($ this ->option ('view ' ) !== false ) {
54
+ $ this ->writeView ();
55
+ }
51
56
}
52
57
53
58
/**
@@ -61,13 +66,33 @@ protected function writeMarkdownTemplate()
61
66
str_replace ('. ' , '/ ' , $ this ->getView ()).'.blade.php '
62
67
);
63
68
64
- if (! $ this ->files ->isDirectory (dirname ($ path ))) {
65
- $ this ->files ->makeDirectory (dirname ($ path ), 0755 , true );
66
- }
69
+ $ this ->files ->ensureDirectoryExists (dirname ($ path ));
67
70
68
71
$ this ->files ->put ($ path , file_get_contents (__DIR__ .'/stubs/markdown.stub ' ));
69
72
}
70
73
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
+
71
96
/**
72
97
* Build the class with the given name.
73
98
*
@@ -82,7 +107,7 @@ protected function buildClass($name)
82
107
parent ::buildClass ($ name )
83
108
);
84
109
85
- if ($ this ->option ('markdown ' ) !== false ) {
110
+ if ($ this ->option ('markdown ' ) !== false || $ this -> option ( ' view ' ) !== false ) {
86
111
$ class = str_replace (['DummyView ' , '{{ view }} ' ], $ this ->getView (), $ class );
87
112
}
88
113
@@ -96,7 +121,7 @@ protected function buildClass($name)
96
121
*/
97
122
protected function getView ()
98
123
{
99
- $ view = $ this ->option ('markdown ' );
124
+ $ view = $ this ->option ('markdown ' ) ?: $ this -> option ( ' view ' ) ;
100
125
101
126
if (! $ view ) {
102
127
$ name = str_replace ('\\' , '/ ' , $ this ->argument ('name ' ));
@@ -116,10 +141,15 @@ protected function getView()
116
141
*/
117
142
protected function getStub ()
118
143
{
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 ' );
123
153
}
124
154
125
155
/**
@@ -156,6 +186,7 @@ protected function getOptions()
156
186
return [
157
187
['force ' , 'f ' , InputOption::VALUE_NONE , 'Create the class even if the mailable already exists ' ],
158
188
['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 ],
159
190
];
160
191
}
161
192
}
0 commit comments