Skip to content

Commit 7c57100

Browse files
committed
Overrides service provider if needed
1 parent bb2d665 commit 7c57100

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace App\Providers;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
use Illuminate\Auth\Middleware\redirectUsing;
7+
8+
class AppServiceProvider extends ServiceProvider
9+
{
10+
/**
11+
* Register any application services.
12+
*/
13+
public function register(): void
14+
{
15+
//
16+
}
17+
18+
/**
19+
* Bootstrap any application services.
20+
*/
21+
public function boot(): void
22+
{
23+
RedirectIfAuthenticated::redirectUsing(fn () => '/');
24+
}
25+
}

src/AuthCommand.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,33 @@ 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('HomeController'));
120+
file_put_contents($controller, $this->compileStub('controllers/HomeController'));
121121
}
122122
} else {
123-
file_put_contents($controller, $this->compileControllerStub('HomeController'));
123+
file_put_contents($controller, $this->compileStub('controllers/HomeController'));
124124
}
125125

126126
$baseController = app_path('Http/Controllers/Controller.php');
127127

128128
if (file_exists($baseController) && ! $this->option('force')) {
129129
if ($this->components->confirm("The [Controller.php] file already exists. Do you want to replace it?")) {
130-
file_put_contents($baseController, $this->compileControllerStub('Controller'));
130+
file_put_contents($baseController, $this->compileStub('controllers/Controller'));
131131
}
132132
} else {
133-
file_put_contents($baseController, $this->compileControllerStub('Controller'));
133+
file_put_contents($baseController, $this->compileStub('controllers/Controller'));
134+
}
135+
136+
if (class_exists('Illuminate\Auth\Middleware\RedirectIfAuthenticated')
137+
&& method_exists('Illuminate\Auth\Middleware\RedirectIfAuthenticated', 'redirectUsing')) {
138+
$appProvider = app_path('Providers/AppServiceProvider.php');
139+
140+
if (file_exists($appProvider) && ! $this->option('force')) {
141+
if ($this->components->confirm("The [AppServiceProvider.php] file already exists. Do you want to replace it?")) {
142+
file_put_contents($appProvider, $this->compileStub('providers/AppServiceProvider'));
143+
}
144+
} else {
145+
file_put_contents($appProvider, $this->compileStub('providers/AppServiceProvider'));
146+
}
134147
}
135148

136149
file_put_contents(
@@ -151,12 +164,12 @@ protected function exportBackend()
151164
* @param string $stub
152165
* @return string
153166
*/
154-
protected function compileControllerStub($stub)
167+
protected function compileStub($stub)
155168
{
156169
return str_replace(
157170
'{{namespace}}',
158171
$this->laravel->getNamespace(),
159-
file_get_contents(__DIR__.'/Auth/stubs/controllers/'.$stub.'.stub')
172+
file_get_contents(__DIR__.'/Auth/stubs/'.$stub.'.stub')
160173
);
161174
}
162175

0 commit comments

Comments
 (0)