public function run(){
$types = ['Travelling','Camping','Restaurants','Food'];
for ($i = 0; $i < 50; $i++){
$faker = Factory::create();
$internet = new Internet($faker);
$date = new DateTime($faker);
$lorem = new Lorem($faker);
$id = $internet->numberBetween($min = 2000,$max = 2000000);
$price = $internet->randomFloat($nbMaxDecimals = 2, $min = 0, $max = 100);
$expiration = $date->dateTimeBetween($startDate = 'now', $endDate = '+2 years');
$title = $lorem->sentence($nbWords = 3, $variableNbWords = true);
DB::table('coupon')->insert([
'id'=>$id,
'title'=>$title,
'price'=>$price,
"type"=>$types[$i],
'expiration'=>$expiration
]);
}
}
该表更新了4行。需要您的帮助,不明白如何克服偏移量限制吗?还有其他配置吗?
Illuminate \ Foundation \ Bootstrap \ HandleExceptions :: handleError(“未定义偏移量:4”,“ C:\ xampp \ htdocs \ couponsystem \ database \ seeds \ CouponSeeder.php”]
肯定是因为您的变量类型仅由4个元素组成,并且当foor循环中的变量i为4时,它将引发未定义偏移量4的错误。解决这个问题。
更改此,“类型” => $ types [$ i]
收件人,“类型” => $ types [rand(0,3)]