①tinker
ディレクトリ移動
公文)
$ cd /Applications/MAMP/htdocs/プロジェクト名
例)
$ cd /Applications/MAMP/htdocs/laravel_test
tinkerでテーブルにレコード追加
$ php artisan tinker
>>> $test = new App\Models\Test;
>>> $test->text = "aaa";
=> "aaa"
>>> $test->save();
=> true
>>> App\Models\Test::all();
=> Illuminate\Database\Eloquent\Collection {#3054
all: [
App\Models\Test {#3055
id: 1,
text: "aaa",
created_at: "2020-05-05 17:27:03",
updated_at: "2020-05-05 17:27:03",
},
],
}
>>>
>>> $test2 = new App\Models\Test;
>>> $test2->text = “bbb”;
=> "bbb"
>>> $test2->save();
=> true
>>> App\Models\Test::all();
=> Illuminate\Database\Eloquent\Collection {#3058
all: [
App\Models\Test {#3059
id: 1,
text: "aaa",
created_at: "2020-05-05 17:27:03",
updated_at: "2020-05-05 17:27:03",
},
App\Models\Test {#3060
id: 2,
text: "bbb",
created_at: "2020-05-05 17:33:26",
updated_at: "2020-05-05 17:33:26",
},
],
}
>>>
②テーブル更新確認
MAMPを開く
http://localhost:8888/phpMyAdmin/server_databases.php
テーブル(Test)の中身が更新されていることを確認