예제 #1
0
 public function testAticleHit()
 {
     $hit = ArticleHit::find(30);
     $this->assertSame(['id' => 30, 'article_id' => 143, 'user_id' => 20], $hit->toArray());
     $this->assertInstanceOf(Article::class, $hit->article);
     $this->assertSame(['id' => 143, 'username' => 'rosina.conn', 'content' => 'Perspiciatis molestiae distinctio consequuntur aut rerum. ' . 'Sunt culpa assumenda sapiente quia.', 'vote' => 0, 'created_at' => '2015-08-27 20:42:29', 'updated_at' => '2015-08-27 20:42:29'], $hit->article->toArray());
     $this->assertInstanceOf(User::class, $hit->user);
     $this->assertSame(['id' => 20, 'username' => 'graham.otto', 'created_at' => '2015-08-27 20:42:28'], $hit->user->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)]);
}