Laravel 5.1では、5.0の時に標準で入っていた Bootstrap3の認証用のビューが削除されてしまいました。CSSフレームワークは必ずしもBootstrap3を使うわけでは無いのは分かるのですが、これはこれでちょっと不便になった気もします。
そこで、認証用のビューを簡単にセットアップできる bestmomo/scafold パッケージを紹介します。
https://github.com/bestmomo/scafold
インストール
composer でパッケージをインストールします。
composer require bestmomo/scafold:dev-master
config/app.php にサービスプロバイダーを登録します。
Bestmomo\Scafold\ScafoldServiceProvider::class,
Publish
viewやassetsをパッケージからアプリのディレクトリにコピーします。
php artisan vendor:publish
以下のファイルがコピーされます。
resources/views ├── auth │ ├── login.blade.php │ ├── password.blade.php │ ├── register.blade.php │ └── reset.blade.php ├── emails │ └── password.blade.php ├── app.blade.php └── home.blade.php public/ ├── css │ └── app.css └── fonts ├── glyphicons-halflings-regular.eot ├── glyphicons-halflings-regular.svg ├── glyphicons-halflings-regular.ttf ├── glyphicons-halflings-regular.woff └── glyphicons-halflings-regular.woff2
ルートの確認
php artisan route:list
+--------+--------------------------------+-------------------------------------------------------+------+------------------------------------------------------------+------------+ | Domain | Method | URI | Name | Action | Middleware | +--------+--------------------------------+-------------------------------------------------------+------+------------------------------------------------------------+------------+ | | GET|HEAD | home | | \Bestmomo\Scafold\Http\Controllers\HomeController@index | auth | | | GET|HEAD | auth/login/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController@getLogin | guest | | | POST | auth/login/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController@postLogin | guest | | | GET|HEAD | auth/logout/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController@getLogout | | | | GET|HEAD | auth/register/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController@getRegister | guest | | | POST | auth/register/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController@postRegister | guest | | | GET|HEAD|POST|PUT|PATCH|DELETE | auth/{_missing} | | App\Http\Controllers\Auth\AuthController@missingMethod | guest | | | GET|HEAD | password/email/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController@getEmail | guest | | | POST | password/email/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController@postEmail | guest | | | GET|HEAD | password/reset/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController@getReset | guest | | | POST | password/reset/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController@postReset | guest | | | GET|HEAD|POST|PUT|PATCH|DELETE | password/{_missing} | | App\Http\Controllers\Auth\PasswordController@missingMethod | guest | +--------+--------------------------------+-------------------------------------------------------+------+------------------------------------------------------------+------------+
ログイン、ログアウト、ユーザー登録、パスワードの再設定が利用可能になります。
http://localhost:8000/home
http://localhost:8000/auth/login
http://localhost:8000/auth/register
http://localhost:8000/password/email
ちょっとした、サンプルを作るときには、とても助かるパッケージです。