:::

5-5 /database/factories/TopicFactory.php

<?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, 9);
    $num2 = rand(1, 9);

    return [
        'topic'           => "$num1 x $num2 = ?",
        'opt' . $items[0] => $num1 * $num2,
        'opt' . $items[1] => $num1 + $num2,
        'opt' . $items[2] => $num1 . $num2,
        'opt' . $items[3] => $num2 . $num1,
        'ans'             => $items[0],
        'created_at'      => $random_date,
        'updated_at'      => $random_date,
    ];
});

 


:::

書籍目錄

展開 | 闔起

快速登入


http%3A%2F%2Fcampus-xoops.tn.edu.tw%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D1320%26tbsn%3D41

計數器

今天: 532532532
昨天: 8625862586258625
總計: 8031139803113980311398031139803113980311398031139