ここでは,プロジェクトにユーザ認証の機能を追加する.つまり,ユーザの登録やログイン,ログアウト,ユーザごとに違った内容のページを表示させる機能の実現である.
プロジェクトを作成する.すでにあるプロジェクトに機能を追加する場合は以下の作業は不要です.
[GakuinHana@rin06 Documents]$ pwd ⏎
/home/GakuinHana/Documents
[GakuinHana@rin06 Documents]$ cd laravel/ ⏎
[GakuinHana@rin06 laravel]$ ls ⏎
composer.phar
[GakuinHana@rin06 laravel]$ php composer.phar create-project --prefer-dist laravel/laravel laravelUser ⏎
You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug
Installing laravel/laravel (v5.4.30)
- Installing laravel/laravel (v5.4.30)
Downloading: 100%
Created project in laravelUser
...(中略)...
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
Generating optimized class loader
The compiled services file has been removed.
> php artisan key:generate
Application key [base64:zKbvG7T0j9968O/jC6WtYgP8Uvq2yI4dyNpu8XbH+WM=] set successfully.
[GakuinHana@rin06 laravel]$
Git の初期設定をしているのであれば,Git でコミットしておく.
[GakuinHana@rin06 laravel]$ cd laravelUser ⏎
[GakuinHana@rin06 laravelUser]$ ls ⏎
app composer.json database public routes tests
artisan composer.lock package.json readme.md server.php vendor
bootstrap config phpunit.xml resources storage webpack.mix.js
[GakuinHana@rin06 laravelUser]$ git init ⏎
Initialized empty Git repository in /home/GakuinHana/Documents/laravel/laravelUser/.git/
[GakuinHana@rin06 laravelUser]$ git add . ⏎
[GakuinHana@rin06 laravelUser]$ git commit -m"initial commit" ⏎
[master (root-commit) 3fa9439] initial commit
81 files changed, 6481 insertions(+)
...(中略)...
[GakuinHana@rin06 laravelUser]$ git log ⏎
commit 3fa94396620e7b32f5a6ac6e50444c753973b176
Author: Gakuin Hanako <gakuin.hanako@dummy.kobegakuin.ac.jp>
Date: Thu Jun 14 13:10:55 2018 +0900
initial commit
[GakuinHana@rin06 laravelUser]$
.env ファイルを修正する.DB_CONNECTIONをsqliteに変更し,DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD の行を削除するか,先頭に # を付けてコメントアウトする.
.env (抜粋)
DB_CONNECTION=sqlite
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=homestead
# DB_USERNAME=homestead
# DB_PASSWORD=secret
プロジェクトの設定ファイル config/app.php を編集し,タイムゾーンをAsia/Tokyoに,言語をjaに変更する.
config/app.php (抜粋)
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
*/
'timezone' => 'Asia/Tokyo',
/*
|--------------------------------------------------------------------------
| Application Locale Configuration
|--------------------------------------------------------------------------
|
| The application locale determines the default locale that will be used
| by the translation service provider. You are free to set this value
| to any of the locales which will be supported by the application.
|
*/
'locale' => 'ja',
Sqlite用に空のデータベースファイル database/database.sqlite を作成する.
[GakuinHana@rin06 laravelUser]$ ls ⏎ app composer.json database public routes tests artisan composer.lock package.json readme.md server.php vendor bootstrap config phpunit.xml resources storage webpack.mix.js [GakuinHana@rin06 laravelUser]$ cd database ⏎ [GakuinHana@rin06 database]$ ls ⏎ factories migrations seeds [GakuinHana@rin06 database]$ touch database.sqlite ⏎ [GakuinHana@rin06 database]$ ls ⏎ database.sqlite factories migrations seeds [GakuinHana@rin06 database]$ cd .. ⏎ [GakuinHana@rin06 laravelUser]$