一応メモっとく.
プロジェクトを作る&バージョン確認
codeというプロジェクトを作成.
vagrant@homestead:~$ composer create-project --prefer-dist laravel/laravel code
バージョンは5.7.4
vagrant@homestead:~/code$ php artisan --version
PostgreSQLのバージョンを確認
vagrant@homestead:~/code$ psql --version psql (PostgreSQL) 10.3 (Ubuntu 10.3-1)
とりあえずpsqlでつないでみる
- ユーザーはhomestead
- パスワードはsecret
- データベースはhomestead
で最初から用意されていた.
vagrant@homestead:~/code$ psql -U homestead -h localhost Password for user homestead: psql (10.3 (Ubuntu 10.3-1)) SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off) Type "help" for help. homestead=#
Laravelの環境設定
.envに書いてあるので変更します.
vagrant@homestead:~/code$ pwd /home/vagrant/code vagrant@homestead:~/code$ vi .env
mysqlがデフォルトなのでpgsqlへ変更. ポート番号も変えておく.
#DB_CONNECTION=mysql DB_CONNECTION=pgsql DB_HOST=127.0.0.1 #DB_PORT=3306 DB_PORT=5432 DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret
マイグレーションしてみる
プロジェクト作成時に用意されるusersテーブルをマイグレーションしてみる.
vagrant@homestead:~/code$ php artisan migrate Migration table created successfully. Migrating: 2014_10_12_000000_create_users_table Migrated: 2014_10_12_000000_create_users_table Migrating: 2014_10_12_100000_create_password_resets_table Migrated: 2014_10_12_100000_create_password_resets_table
確認
一式生成されていた.
vagrant@homestead:~/code$ psql -U homestead -h localhost Password for user homestead: psql (10.3 (Ubuntu 10.3-1)) SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off) Type "help" for help. homestead=# \d List of relations Schema | Name | Type | Owner --------+-------------------+----------+----------- public | migrations | table | homestead public | migrations_id_seq | sequence | homestead public | password_resets | table | homestead public | users | table | homestead public | users_id_seq | sequence | homestead (5 rows) homestead=#
とても簡単だ.良く出来ている.