I had checked for this issue but didn't found the solution that fits my need.
I had created the table for State, City & Locality with 37, 7431 & 91853 records are available.
It was taking longer time when I was using create instead of using insert in seeder.
So, I changed my code by replacing create to insert. Then got to know about the chunk by Laravel Daily Video.
The Chunk is working fine in the CitySeeder but got the issue in LocalitySeeder.
This is the code in my Seeder:
<?php
namespace Database\Seeders;
use App\Models\Locality;
use Illuminate\Database\Seeder;
class LocalitySeeder extends Seeder
{
public function run()
{
$input = [
[ 'name' => 'Adilabad', 'city_id' => 5487, 'created_at' => now()->toDateTimeString(), 'updated_at' => now()->toDateTimeString() ],
.
.
.
.
.
.
.
.
[ 'name' => 'Nalgonda', 'city_id' => 5476, 'created_at' => now()->toDateTimeString(), 'updated_at' => now()->toDateTimeString() ],];
$chunks = array_chunk($input, 5000, true);
foreach ($chunks as $key => $data) {
Locality::insert($data);
}
}
}
Thanks in Advance.