diff --git a/src/Seeds/CitiesSeeder.php b/src/Seeds/CitiesSeeder.php index 178e71f..423b7ef 100644 --- a/src/Seeds/CitiesSeeder.php +++ b/src/Seeds/CitiesSeeder.php @@ -2,6 +2,7 @@ namespace Laravolt\Indonesia\Seeds; +use Carbon\Carbon; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; @@ -9,15 +10,16 @@ class CitiesSeeder extends Seeder { public function run() { + $now = Carbon::now(); $Csv = new CsvtoArray(); $file = __DIR__.'/../../resources/csv/cities.csv'; $header = ['id', 'province_id', 'name', 'lat', 'long']; $data = $Csv->csv_to_array($file, $header); - $data = array_map(function ($arr) { + $data = array_map(function ($arr) use ($now) { $arr['meta'] = json_encode(['lat' => $arr['lat'], 'long' => $arr['long']]); unset($arr['lat'], $arr['long']); - return $arr + ['created_at' => now(), 'updated_at' => now()]; + return $arr + ['created_at' => $now, 'updated_at' => $now]; }, $data); $collection = collect($data); diff --git a/src/Seeds/DistrictsSeeder.php b/src/Seeds/DistrictsSeeder.php index f575334..9ee09d8 100644 --- a/src/Seeds/DistrictsSeeder.php +++ b/src/Seeds/DistrictsSeeder.php @@ -2,6 +2,7 @@ namespace Laravolt\Indonesia\Seeds; +use Carbon\Carbon; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; @@ -9,15 +10,16 @@ class DistrictsSeeder extends Seeder { public function run() { + $now = Carbon::now(); $csv = new CsvtoArray(); $file = __DIR__.'/../../resources/csv/districts.csv'; $header = ['id', 'city_id', 'name', 'lat', 'long']; $data = $csv->csv_to_array($file, $header); - $data = array_map(function ($arr) { + $data = array_map(function ($arr) use ($now) { $arr['meta'] = json_encode(['lat' => $arr['lat'], 'long' => $arr['long']]); unset($arr['lat'], $arr['long']); - return $arr + ['created_at' => now(), 'updated_at' => now()]; + return $arr + ['created_at' => $now, 'updated_at' => $now]; }, $data); $collection = collect($data); diff --git a/src/Seeds/ProvincesSeeder.php b/src/Seeds/ProvincesSeeder.php index c8d2156..b4a9a16 100644 --- a/src/Seeds/ProvincesSeeder.php +++ b/src/Seeds/ProvincesSeeder.php @@ -2,6 +2,7 @@ namespace Laravolt\Indonesia\Seeds; +use Carbon\Carbon; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; @@ -9,15 +10,16 @@ class ProvincesSeeder extends Seeder { public function run() { + $now = Carbon::now(); $csv = new CsvtoArray(); $file = __DIR__.'/../../resources/csv/provinces.csv'; $header = ['id', 'name', 'lat', 'long']; $data = $csv->csv_to_array($file, $header); - $data = array_map(function ($arr) { + $data = array_map(function ($arr) use ($now) { $arr['meta'] = json_encode(['lat' => $arr['lat'], 'long' => $arr['long']]); unset($arr['lat'], $arr['long']); - return $arr + ['created_at' => now(), 'updated_at' => now()]; + return $arr + ['created_at' => $now, 'updated_at' => $now]; }, $data); DB::table(config('laravolt.indonesia.table_prefix').'provinces')->insert($data); diff --git a/src/Seeds/VillagesSeeder.php b/src/Seeds/VillagesSeeder.php index b3ae1f4..c7c3c58 100644 --- a/src/Seeds/VillagesSeeder.php +++ b/src/Seeds/VillagesSeeder.php @@ -2,6 +2,7 @@ namespace Laravolt\Indonesia\Seeds; +use Carbon\Carbon; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\File; @@ -10,17 +11,18 @@ class VillagesSeeder extends Seeder { public function run() { + $now = Carbon::now(); $csv = new CsvtoArray(); $resourceFiles = File::allFiles(__DIR__.'/../../resources/csv/villages'); foreach ($resourceFiles as $file) { $header = ['id', 'district_id', 'name', 'lat', 'long']; $data = $csv->csv_to_array($file->getRealPath(), $header); - $data = array_map(function ($arr) { + $data = array_map(function ($arr) use ($now) { $arr['meta'] = json_encode(['lat' => $arr['lat'], 'long' => $arr['long']]); unset($arr['lat'], $arr['long']); - return $arr + ['created_at' => now(), 'updated_at' => now()]; + return $arr + ['created_at' => $now, 'updated_at' => $now]; }, $data); $collection = collect($data);