2
2
3
3
namespace Inertia \Console ;
4
4
5
- use Illuminate \Console \Command ;
6
- use Throwable ;
7
- use View ;
5
+ use Illuminate \Console \GeneratorCommand ;
8
6
9
- class CreateMiddleware extends Command
7
+ class CreateMiddleware extends GeneratorCommand
10
8
{
11
9
/**
12
10
* The name and signature of the console command.
@@ -23,30 +21,30 @@ class CreateMiddleware extends Command
23
21
protected $ description = 'Creates a new Inertia middleware ' ;
24
22
25
23
/**
26
- * Create a new command instance .
24
+ * The type of class being generated .
27
25
*
28
- * @return void
26
+ * @var string
29
27
*/
30
- public function __construct ()
31
- {
32
- parent ::__construct ();
28
+ protected $ type = 'Middleware ' ;
33
29
34
- View::addNamespace ('inertia ' , __DIR__ .'/../../stubs ' );
30
+ /**
31
+ * Get the stub file for the generator.
32
+ *
33
+ * @return string
34
+ */
35
+ protected function getStub ()
36
+ {
37
+ return __DIR__ .'/../../stubs/middleware.stub ' ;
35
38
}
36
39
37
40
/**
38
- * Execute the console command .
41
+ * Get the default namespace for the class .
39
42
*
40
- * @return void
41
- * @throws Throwable
43
+ * @param string $rootNamespace
44
+ * @return string
42
45
*/
43
- public function handle ( )
46
+ protected function getDefaultNamespace ( $ rootNamespace )
44
47
{
45
- file_put_contents (
46
- app_path ('Http/Middleware/ ' .$ this ->argument ('name ' ).'.php ' ),
47
- view ('inertia::Middleware ' , ['name ' => $ this ->argument ('name ' )])->render ()
48
- );
49
-
50
- $ this ->info ('Inertia middleware [ ' .$ this ->argument ('name ' ).'] created successfully. ' );
48
+ return $ rootNamespace .'\Http\Middleware ' ;
51
49
}
52
50
}
0 commit comments