File: /var/www/gestion-formularios.bdfschool/database/seeders/UploadStudentDebtSeeder.php
<?php
namespace Database\Seeders;
use Carbon\Carbon;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class UploadStudentDebtSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$data = [];
for ($i = 1; $i <= 20; $i++) {
$cancelled = $i <= 2 ? true : false; // Solo 2 registros con "cancelled" en true
$reason_cancelled = $cancelled ? 'Cancelled due to error' : null;
$cancelled_at = $cancelled ? Carbon::now() : null;
$quantity = rand(10, 200);
// Distribuir entre éxitos y errores
$quantity_error = rand(0, $quantity); // Éxitos
$quantity_success = $quantity - $quantity_error;
$data[] = [
'quantity' => $quantity,
'quantity_success' => $quantity_success,
'quantity_error' => $quantity_error,
'user_created' => 1,
'sent' => 1,
'sent_success' => rand(200, 204), // códigos de respuesta HTTP de éxito
'cancelled' => $cancelled,
'reason_cancelled' => $reason_cancelled,
'cancelled_at' => $cancelled_at,
'integration_at' => Carbon::now(),
'integration_status_id' => rand(1, 4),
'status_upload_student_debts_id' => rand(1, 3),
'user_confirmation' => rand(100, 999),
'confirmation_at' => Carbon::now(),
'user_cancelled' => $cancelled ? rand(1, 10) : null,
'created_at' => Carbon::now(),
'updated_at' => Carbon::now()
];
}
DB::table('upload_student_debts')->insert($data);
}
}