Here is my code:
$num = 5;
$voucher = new Voucher;
for ( $i = $num; $i > 0; $i-- ) {
$token = generateRandomString(5, ['number', 'uppercase']);
$voucher->prefix = $request->prefix;
$voucher->token = $token;
$voucher->description = $request->description;
$voucher->date_time = time();
$voucher->save();
}
Obviously my code should insert 5 rows. But surprisingly it inserts only 1 row. What's wrong and how can I fix it?
$voucher = new Voucher;is in for loop!