From 88071c58b9696da98e8b8f2c63defd7d3667ee5a Mon Sep 17 00:00:00 2001 From: Loek van der Linde Date: Mon, 9 Sep 2019 11:05:57 +0200 Subject: [PATCH] Add compatibility with Laravel 6 --- CHANGELOG.md | 9 +- README.md | 8 +- composer.json | 4 +- src/Console/CoreUIAuthCommand.php | 131 ++++++++++++++++++ src/Console/CoreUIMakeCommand.php | 29 ---- .../stubs/controllers/HomeController.stub | 28 ++++ src/Console/stubs/routes.stub | 4 + .../stubs/{make => }/views/auth/login.stub | 0 .../views/auth/passwords/email.stub | 0 .../views/auth/passwords/reset.stub | 0 .../stubs/{make => }/views/auth/register.stub | 0 src/Console/stubs/{make => }/views/home.stub | 11 +- src/ServiceProvider.php | 4 +- 13 files changed, 184 insertions(+), 44 deletions(-) create mode 100644 src/Console/CoreUIAuthCommand.php delete mode 100644 src/Console/CoreUIMakeCommand.php create mode 100644 src/Console/stubs/controllers/HomeController.stub create mode 100644 src/Console/stubs/routes.stub rename src/Console/stubs/{make => }/views/auth/login.stub (100%) rename src/Console/stubs/{make => }/views/auth/passwords/email.stub (100%) rename src/Console/stubs/{make => }/views/auth/passwords/reset.stub (100%) rename src/Console/stubs/{make => }/views/auth/register.stub (100%) rename src/Console/stubs/{make => }/views/home.stub (77%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cd7290..eb25d23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.0.0] - 2019-09-09 +### Changed +- Add compatibility to Laravel 6.0 +- Adhere to laravel/ui package structuring +### Removed +- Compatibility with Laravel 5 + ## [2.9.1] - 2019-07-02 ### Fixed -- File paths so that the CSS and JS on login/register like views will actually load. +- File paths so that the CSS and JS on login/register like views will actually load ## [2.9.0] - 2019-06-13 ### Changed diff --git a/README.md b/README.md index 5a683c2..219cf48 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,14 @@ [![Total Downloads](https://poser.pugx.org/hz-hbo-ict/laravel-core-ui/downloads)](https://packagist.org/packages/hz-hbo-ict/laravel-core-ui) [![License](https://poser.pugx.org/hz-hbo-ict/laravel-core-ui/license)](https://packagist.org/packages/hz-hbo-ict/laravel-core-ui) -This is a very opinionated package designed to help our freshman year's students with rapid prototyping of web applications. +This is an opinionated package designed to help our freshman year's students with rapid prototyping of web applications. The package is based upon [CoreUI](https://coreui.io/), with every plugin we deemed unnecessary removed. -It builds upon the latest stable releases of [Laravel 5](https://laravel.com). As of now, that is version `5.8`. +It builds upon the latest stable releases of [Laravel](https://laravel.com). As of now, that is version `6.0`. -It also incorporates a replacement command for Laravel's [`make:auth`](https://laravel.com/docs/5.8/authentication#introduction) command that uses CoreUI styled views for a more consistent user experience. +It also incorporates a replacement command for Laravel's [`make:auth`](https://laravel.com/docs/6.0/authentication#introduction) command that uses CoreUI styled views for a more consistent user experience. + +The result is an easy to use package that can setup a secure and complete dashboard front-end in a matter of seconds. Adding new views and features is a breeze and doesn't disrupt your normal workflow. ## Installation diff --git a/composer.json b/composer.json index a78723d..f62c5e8 100644 --- a/composer.json +++ b/composer.json @@ -34,8 +34,8 @@ } }, "require": { - "php": ">=7.1.3", - "laravel/framework": "~5.8.0" + "php": "^7.2", + "laravel/framework": "^6.0" }, "minimum-stability": "dev", "prefer-stable": true diff --git a/src/Console/CoreUIAuthCommand.php b/src/Console/CoreUIAuthCommand.php new file mode 100644 index 0000000..82a3c7f --- /dev/null +++ b/src/Console/CoreUIAuthCommand.php @@ -0,0 +1,131 @@ + '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, + ]); + } +} diff --git a/src/Console/CoreUIMakeCommand.php b/src/Console/CoreUIMakeCommand.php deleted file mode 100644 index 7119e7c..0000000 --- a/src/Console/CoreUIMakeCommand.php +++ /dev/null @@ -1,29 +0,0 @@ - 'auth/login.blade.php', - 'auth/register.stub' => 'auth/register.blade.php', - 'auth/passwords/email.stub' => 'auth/passwords/email.blade.php', - 'auth/passwords/reset.stub' => 'auth/passwords/reset.blade.php', - 'home.stub' => 'home.blade.php' - ]; - - foreach ($views as $stub => $view) { - copy(__DIR__.'/stubs/make/views/' . $stub, base_path('resources/views/' . $view)); - } - } -} diff --git a/src/Console/stubs/controllers/HomeController.stub b/src/Console/stubs/controllers/HomeController.stub new file mode 100644 index 0000000..63a1e36 --- /dev/null +++ b/src/Console/stubs/controllers/HomeController.stub @@ -0,0 +1,28 @@ +middleware('auth'); + } + + /** + * Show the application dashboard. + * + * @return \Illuminate\Contracts\Support\Renderable + */ + public function index() + { + return view('home'); + } +} diff --git a/src/Console/stubs/routes.stub b/src/Console/stubs/routes.stub new file mode 100644 index 0000000..2c37ded --- /dev/null +++ b/src/Console/stubs/routes.stub @@ -0,0 +1,4 @@ + +Auth::routes(); + +Route::get('/home', 'HomeController@index')->name('home'); diff --git a/src/Console/stubs/make/views/auth/login.stub b/src/Console/stubs/views/auth/login.stub similarity index 100% rename from src/Console/stubs/make/views/auth/login.stub rename to src/Console/stubs/views/auth/login.stub diff --git a/src/Console/stubs/make/views/auth/passwords/email.stub b/src/Console/stubs/views/auth/passwords/email.stub similarity index 100% rename from src/Console/stubs/make/views/auth/passwords/email.stub rename to src/Console/stubs/views/auth/passwords/email.stub diff --git a/src/Console/stubs/make/views/auth/passwords/reset.stub b/src/Console/stubs/views/auth/passwords/reset.stub similarity index 100% rename from src/Console/stubs/make/views/auth/passwords/reset.stub rename to src/Console/stubs/views/auth/passwords/reset.stub diff --git a/src/Console/stubs/make/views/auth/register.stub b/src/Console/stubs/views/auth/register.stub similarity index 100% rename from src/Console/stubs/make/views/auth/register.stub rename to src/Console/stubs/views/auth/register.stub diff --git a/src/Console/stubs/make/views/home.stub b/src/Console/stubs/views/home.stub similarity index 77% rename from src/Console/stubs/make/views/home.stub rename to src/Console/stubs/views/home.stub index eace3e2..d390009 100644 --- a/src/Console/stubs/make/views/home.stub +++ b/src/Console/stubs/views/home.stub @@ -3,19 +3,16 @@ @section('title', 'CoreUI') @section('body') -

You are logged in!

-

See the official CoreUI docs to see how to build your amazing app!

-
- Featured + Woohoo!
-
Special title treatment
-

It's a broader card with text below as a natural lead-in to extra content. This content is a little longer.

- Go somewhere +
You are now logged in!
+

Click on the button below to visit the official CoreUI documentation and learn how to build an amazing app.

+ Take me to CoreUI
diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 5eaa8c7..a35818f 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -2,7 +2,7 @@ namespace HzHboIct\LaravelCoreUI; -use HzHboIct\LaravelCoreUI\Console\CoreUIMakeCommand; +use HzHboIct\LaravelCoreUI\Console\CoreUIAuthCommand; use HzHboIct\LaravelCoreUI\Events\BuildingMenu; use HzHboIct\LaravelCoreUI\Http\ViewComposers\CoreUIComposer; use Illuminate\Contracts\Config\Repository; @@ -75,7 +75,7 @@ private function publishAssets(): void private function publishCommands(): void { - $this->commands(CoreUIMakeCommand::class); + $this->commands(CoreUIAuthCommand::class); } private function publishViews(): void