[vagrant@localhost myblog]$ php artisan tinker
Psy Shell v0.9.8 (PHP 7.1.21 — cli) by Justin Hileman
>>> $post = new App\Post();
=> App\Post {#2900}
>>> $post->title = 'title 1';
=> "title 1"
>>> $post->body = 'body 1';
=> "body 1"
>>> $post->save();
=> true
>>> App\Post::all();
=> Illuminate\Database\Eloquent\Collection {#2908
all: [
App\Post {#2909
id: "1",
title: "title 1",
body: "body 1",
created_at: "2018-09-08 23:21:01",
updated_at: "2018-09-08 23:21:01",
},
],
}
>>> App\Post::all()->toArray();
=> [
[
"id" => 1,
"title" => "title 1",
"body" => "body 1",
"created_at" => "2018-09-08 23:21:01",
"updated_at" => "2018-09-08 23:21:01",
],
]
sqliteで見てみます。
[vagrant@localhost myblog]$ sqlite3 database/database.sqlite
SQLite version 3.6.20
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select * from posts;
1|title 1|body 1|2018-09-08 23:21:01|2018-09-08 23:21:01
appの中のpost.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
//
protected $fillable = ['title', 'body'];
}
[vagrant@localhost myblog]$ php artisan tinker
Psy Shell v0.9.8 (PHP 7.1.21 — cli) by Justin Hileman
>>> App\Post::create([‘title’=>’title 2’, ‘body’=>’body 2’]);
=> App\Post {#2898
title: “title 2”,
body: “body 2”,
updated_at: “2018-09-08 23:31:24”,
created_at: “2018-09-08 23:31:24”,
id: 2,
}
>>> App\Post::create([‘title’=>’title 3’, ‘body’=>’body 3’]);
=> App\Post {#2906
title: “title 3”,
body: “body 3”,
updated_at: “2018-09-08 23:32:01”,
created_at: “2018-09-08 23:32:01”,
id: 3,
}
>>> App\Post::all()->toArray();
=> [
[
“id” => 1,
“title” => “title 1”,
“body” => “body 1”,
“created_at” => “2018-09-08 23:21:01”,
“updated_at” => “2018-09-08 23:21:01”,
],
[
“id” => 2,
“title” => “title 2”,
“body” => “body 2”,
“created_at” => “2018-09-08 23:31:24”,
“updated_at” => “2018-09-08 23:31:24”,
],
[
“id” => 3,
“title” => “title 3”,
“body” => “body 3”,
“created_at” => “2018-09-08 23:32:01”,
“updated_at” => “2018-09-08 23:32:01”,
],
]