0
0

More than 3 years have passed since last update.

【Laravel】Laravel tinker

Posted at

①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)の中身が更新されていることを確認

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0