Skip to content

Commit f05765f

Browse files
committed
Injects Controller stub
1 parent 327c798 commit f05765f

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace {{namespace}}Http\Controllers;
4+
5+
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
6+
use Illuminate\Foundation\Validation\ValidatesRequests;
7+
use Illuminate\Routing\Controller as BaseController;
8+
9+
class Controller extends BaseController
10+
{
11+
use AuthorizesRequests, ValidatesRequests;
12+
}

src/AuthCommand.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,20 @@ protected function exportBackend()
117117

118118
if (file_exists($controller) && ! $this->option('force')) {
119119
if ($this->components->confirm("The [HomeController.php] file already exists. Do you want to replace it?")) {
120-
file_put_contents($controller, $this->compileControllerStub());
120+
file_put_contents($controller, $this->compileControllerStub('HomeController'));
121121
}
122122
} else {
123-
file_put_contents($controller, $this->compileControllerStub());
123+
file_put_contents($controller, $this->compileControllerStub('HomeController'));
124+
}
125+
126+
$baseController = app_path('Http/Controllers/Controller.php');
127+
128+
if (file_exists($baseController) && ! $this->option('force')) {
129+
if ($this->components->confirm("The [Controller.php] file already exists. Do you want to replace it?")) {
130+
file_put_contents($baseController, $this->compileControllerStub('Controller'));
131+
}
132+
} else {
133+
file_put_contents($baseController, $this->compileControllerStub('Controller'));
124134
}
125135

126136
file_put_contents(
@@ -138,14 +148,15 @@ protected function exportBackend()
138148
/**
139149
* Compiles the "HomeController" stub.
140150
*
151+
* @param string $stub
141152
* @return string
142153
*/
143-
protected function compileControllerStub()
154+
protected function compileControllerStub($stub)
144155
{
145156
return str_replace(
146157
'{{namespace}}',
147158
$this->laravel->getNamespace(),
148-
file_get_contents(__DIR__.'/Auth/stubs/controllers/HomeController.stub')
159+
file_get_contents(__DIR__.'/Auth/stubs/controllers/'.$stub.'.stub')
149160
);
150161
}
151162

0 commit comments

Comments
 (0)