where('crop_type', 1)->get(); $insertData = []; foreach ($crops as $crop) { $base = AgriculturalBase::where('type', 1)->inRandomOrder()->first(); for($i = 2019; $i < 2023; $i++){ for($j = 1; $j< 5; $j++) { $insertData[] = [ 'base_id' => $base->id, 'crop_id' => $crop->id, 'category_id' => $crop->category_id, 'time_year' => $i, 'quarter' => $j, 'yield' => rand(10000, 99999), 'cultivated'=> rand(100, 999), 'output'=> rand(100000, 999999), ]; } } } if(count($insertData) > 1){ DB::table('crop_yields')->truncate(); CropYield::insert($insertData); } } }