This repository has been archived by the owner on Oct 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17683f1
commit 88071c5
Showing
13 changed files
with
184 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?php | ||
|
||
namespace HzHboIct\LaravelCoreUI\Console; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
class CoreUIAuthCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'ui:coreui | ||
{--views : Only scaffold the authentication views} | ||
{--force : Overwrite existing views by default}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Scaffold basic CoreUI login and registration views and routes'; | ||
|
||
/** | ||
* The views that need to be exported. | ||
* | ||
* @var array | ||
*/ | ||
protected $views = [ | ||
'auth/login.stub' => 'auth/login.blade.php', | ||
'auth/passwords/email.stub' => 'auth/passwords/email.blade.php', | ||
'auth/passwords/reset.stub' => 'auth/passwords/reset.blade.php', | ||
'auth/register.stub' => 'auth/register.blade.php', | ||
'home.stub' => 'home.blade.php', | ||
]; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
$this->ensureDirectoriesExist(); | ||
$this->exportViews(); | ||
|
||
if (! $this->option('views')) { | ||
$this->exportBackend(); | ||
} | ||
|
||
$this->info('Authentication scaffolding generated successfully.'); | ||
} | ||
|
||
/** | ||
* Create the directories for the files. | ||
* | ||
* @return void | ||
*/ | ||
protected function ensureDirectoriesExist() | ||
{ | ||
if (! is_dir($directory = $this->getViewPath('auth/passwords'))) { | ||
mkdir($directory, 0755, true); | ||
} | ||
} | ||
|
||
/** | ||
* Export the authentication views. | ||
* | ||
* @return void | ||
*/ | ||
protected function exportViews() | ||
{ | ||
foreach ($this->views as $stub => $view) { | ||
if (file_exists($view = $this->getViewPath($view)) && ! $this->option('force')) { | ||
if (! $this->confirm('The [' . $view . '] view already exists. Do you want to replace it?')) { | ||
continue; | ||
} | ||
} | ||
copy( | ||
__DIR__ . '/stubs/views/' . $stub, | ||
$view | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Export the authentication backend. | ||
* | ||
* @return void | ||
*/ | ||
protected function exportBackend() | ||
{ | ||
file_put_contents( | ||
app_path('Http/Controllers/HomeController.php'), | ||
$this->compileControllerStub() | ||
); | ||
file_put_contents( | ||
base_path('routes/web.php'), | ||
file_get_contents(__DIR__.'/stubs/routes.stub'), | ||
FILE_APPEND | ||
); | ||
} | ||
|
||
/** | ||
* Compiles the "HomeController" stub. | ||
* | ||
* @return string | ||
*/ | ||
protected function compileControllerStub() | ||
{ | ||
return str_replace( | ||
'{{namespace}}', | ||
$this->laravel->getNamespace(), | ||
file_get_contents(__DIR__.'/stubs/controllers/HomeController.stub') | ||
); | ||
} | ||
|
||
/** | ||
* Get full view path relative to the application's configured view path. | ||
* | ||
* @param string $path | ||
* @return string | ||
*/ | ||
protected function getViewPath($path) | ||
{ | ||
return implode(DIRECTORY_SEPARATOR, [ | ||
config('view.paths')[0] ?? resource_path('views'), $path, | ||
]); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace {{namespace}}Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
class HomeController extends Controller | ||
{ | ||
/** | ||
* Create a new controller instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->middleware('auth'); | ||
} | ||
|
||
/** | ||
* Show the application dashboard. | ||
* | ||
* @return \Illuminate\Contracts\Support\Renderable | ||
*/ | ||
public function index() | ||
{ | ||
return view('home'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
Auth::routes(); | ||
|
||
Route::get('/home', 'HomeController@index')->name('home'); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters