Skip to content

Commit

Permalink
fix: gunakan Carbon::now()
Browse files Browse the repository at this point in the history
Karena helper `now()` tidak tersedia di Lumen
  • Loading branch information
uyab committed Nov 13, 2019
1 parent 4b28c78 commit 183fc4b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/Seeds/CitiesSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@

namespace Laravolt\Indonesia\Seeds;

use Carbon\Carbon;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

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);
Expand Down
6 changes: 4 additions & 2 deletions src/Seeds/DistrictsSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@

namespace Laravolt\Indonesia\Seeds;

use Carbon\Carbon;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

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);
Expand Down
6 changes: 4 additions & 2 deletions src/Seeds/ProvincesSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@

namespace Laravolt\Indonesia\Seeds;

use Carbon\Carbon;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

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);
Expand Down
6 changes: 4 additions & 2 deletions src/Seeds/VillagesSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 183fc4b

Please sign in to comment.