usersテーブルとpasswordsテーブル
sample_app/database/migrations ディレクトリを確認すると、今回のチュートリアルで作成した
- xxxx_create_messages_table.php
- xxxx_add_image_to_messages_table.php
のほかに、
- xxxx_create_users_table.php
- xxxx_create_password_resets_table.php
という2つのマイグレーションファイルがあることがわかります。
実は、Laravelではデフォルトで初回の
php artisan migrate
コマンドを実行した際に、
- ログインユーザーを管理するためのテーブル
- ログインユーザーのパスワード変更を行うための補助的なテーブル
の2つが作成されるようになっているのです。
usersテーブルの内容
マイグレーションファイルの中身をチェックして、usersテーブルの内容を把握しておきましょう。
xxxx_create_users_table.php
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
name, email, password と言う文字列カラムが用意されていることが確認できます。
rememberTokenについては、継続ログインを実現するためのremember_tokenカラムのためのメソッドです。この教科書では詳細は割愛します。