$faker = Faker\Factory::create('zh_TW'); return ['name' => $faker->name, 'describe' => $faker->realText(16), 'category' => Category::getCategories('property')->random()->getAttribute('id'), 'status' => Category::getCategories('property.status')->random()->getAttribute('id'), 'code' => mt_rand(10000000, 99999999)]; }); $factory->define(\App\Affair\Repair::class, function () { $faker = Faker\Factory::create('zh_TW'); return ['user_id' => User::all()->random()->getAttribute('id'), 'title' => mt_rand(0, 1) ? $faker->realText(mt_rand(10, 15)) : '', 'type' => Category::getCategories('repair.type')->random()->getAttribute('id'), 'remark' => $faker->realText(32), 'status' => Category::getCategories('repair.status')->random()->getAttribute('id')]; }); $factory->define(\App\Affair\Loan::class, function () { $faker = Faker\Factory::create('zh_TW'); $time = mt_rand(0, 1); // get randomal Timezone $began_date = Timezone::all()->random()->getAttribute('date_began_at'); $day = (new Carbon($began_date))->addDays(rand(1, 10)); // get date begin/end $begin = $day->toDateString(); $end = $day->addDays(mt_rand(0, 10))->toDateString(); return ['user_id' => User::all()->random()->getAttribute('id'), 'type' => Category::getCategories('loan.type')->random()->getAttribute('id'), 'date_began_at' => $begin, 'date_ended_at' => $end, 'time_began_at' => $time ? $day->addHours(mt_rand(0, 7))->toTimeString() : null, 'time_ended_at' => $time ? $day->addHours(mt_rand(7, 15))->toTimeString() : null, 'remark' => $faker->realText(32), 'status' => Category::getCategories('loan.status')->random()->getAttribute('id'), 'long_term_token' => $begin != $end ? mt_rand(0, 127) : 1 << date('w', strtotime($begin))]; }); $factory->define(\App\Affair\Timezone::class, function () { $faker = Faker\Factory::create('zh_TW'); $day = Carbon::now()->startOfDay()->addDays(mt_rand(1, 365)); $stu_start = clone $day; $lab_start = clone $day; if (mt_rand(0, 1) === 1) { $type = Category::getCategoryId('time.type', 'semester'); } else { $type = Category::getCategoryId('time.type', 'vacation'); $stu_start->subDays(7); } return ['zone_name' => $faker->realText(mt_rand(10, 15)), 'type' => $type, 'date_began_at' => $day->toDateString(), 'date_ended_at' => $day->addDays(mt_rand(30, 150))->toDateString(), 'stu_date_began_at' => $stu_start->toDateString(), 'lab_date_began_at' => $lab_start->toDateString()]; });