Skip to content
This repository has been archived by the owner on Jun 14, 2023. It is now read-only.

Commit

Permalink
利用模型工廠產生隨機題目
Browse files Browse the repository at this point in the history
  • Loading branch information
tad0616 committed Aug 4, 2018
1 parent 9bc6bd2 commit edb6d40
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions database/factories/TopicFactory.php
@@ -0,0 +1,22 @@
<?php

use Faker\Generator as Faker;

$factory->define(App\Topic::class, function (Faker $faker) {
$items = [1, 2, 3, 4];
shuffle($items);

$random_date = $faker->dateTimeBetween('-3 days', '+3 days');
$num1 = rand(1, 99);
$num2 = rand(1, 99);
return [
'topic' => $num1 . " + " . $num2,
'opt' . $items[0] => $num1 + $num2,
'opt' . $items[1] => $num1 . $num2,
'opt' . $items[2] => rand(1, 99),
'opt' . $items[3] => rand(1, 999),
'ans' => $items[0],
'created_at' => $random_date,
'updated_at' => $random_date,
];
});

0 comments on commit edb6d40

Please sign in to comment.