コード例 #1
0
 public function testCategory()
 {
     $category = Category::find(27);
     $this->assertSame(['name' => 'Javascript'], $category->toArray());
     $this->assertSame(['id' => '27', 'article_id' => '34', 'name' => 'Javascript'], $category->getAttributes());
     $this->assertInstanceOf(Article::class, $category->article);
     $this->assertSame(['id' => 34, 'username' => 'candido.walker', 'content' => 'Neque alias officiis sint soluta cupiditate nisi. ' . 'Ut aut amet ipsa ducimus repellat magni. Doloremque omnis possimus cupiditate nostrum autem ut.', 'vote' => 0, 'created_at' => '2015-08-27 20:42:29', 'updated_at' => '2015-08-27 20:42:29'], $category->article->toArray());
 }
コード例 #2
0
	`content`	varchar(100),
	`vote`	INTEGER DEFAULT 0,
	`ancestor_vote`	INTEGER DEFAULT 0,
	`order`	VARBINARY(255) DEFAULT 000,
	`ancestor_order`	VARBINARY(255) DEFAULT 000
);
*/
$capsule->schema()->create('article_hits', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->bigInteger('article_id')->unsingied();
    $table->bigInteger('user_id')->unsingied();
    $table->timestamps();
});
$capsule->schema()->create('categories', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->bigInteger('article_id')->unsigned();
    $table->string('name', 100);
});
$faker = Factory::create();
for ($i = 0; $i < 100; $i++) {
    User::create(['username' => $faker->userName, 'password' => $faker->password]);
}
for ($i = 0; $i < 200; $i++) {
    Article::create(['username' => User::find(rand(1, 100))['username'], 'content' => $faker->text]);
}
for ($i = 0; $i < 200; $i++) {
    Category::create(['article_id' => rand(1, 200), 'name' => ['Q&A', 'PHP', 'FreeBoard', 'Javascript', 'Go'][rand(0, 4)]]);
}
for ($i = 0; $i < 400; $i++) {
    ArticleHit::create(['article_id' => rand(1, 200), 'user_id' => rand(1, 100)]);
}