1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Illuminate\Database\Seeder; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Usage : |
7
|
|
|
* [1] $ composer dump-autoload -o |
8
|
|
|
* [2] $ php artisan db:seed --class=UserSeeder |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
class BantenprovAnggaranSeeder extends Seeder |
12
|
|
|
{ |
13
|
|
|
/* text color */ |
14
|
|
|
protected $RED ="\033[0;31m"; |
15
|
|
|
protected $CYAN ="\033[0;36m"; |
16
|
|
|
protected $YELLOW ="\033[1;33m"; |
17
|
|
|
protected $ORANGE ="\033[0;33m"; |
18
|
|
|
protected $PUR ="\033[0;35m"; |
19
|
|
|
protected $GRN ="\e[32m"; |
20
|
|
|
protected $WHI ="\e[37m"; |
21
|
|
|
protected $NC ="\033[0m"; |
22
|
|
|
|
23
|
|
|
/* File name */ |
24
|
|
|
/* location : /databse/seeds/file_name.csv */ |
25
|
|
|
protected $fileName = "BantenprovAnggaranSeederAnggaran.csv"; |
26
|
|
|
|
27
|
|
|
/* text info : default (true) */ |
28
|
|
|
protected $textInfo = true; |
29
|
|
|
|
30
|
|
|
/* model class */ |
31
|
|
|
protected $model; |
32
|
|
|
|
33
|
|
|
/* __construct */ |
34
|
|
|
public function __construct(){ |
35
|
|
|
|
36
|
|
|
$this->model = new Bantenprov\Anggaran\Models\Bantenprov\Anggaran\Anggaran; |
37
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Run the database seeds. |
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
public function run() |
46
|
|
|
{ |
47
|
|
|
$this->insertData(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/* function insert data */ |
51
|
|
|
protected function insertData() |
52
|
|
|
{ |
53
|
|
|
/* silahkan di rubah sesuai kebutuhan */ |
54
|
|
|
foreach($this->readCSV() as $data){ |
55
|
|
|
|
56
|
|
|
$this->model->create([ |
57
|
|
|
'user_id' => $data['user_id'], |
58
|
|
|
'label' => $data['label'], |
59
|
|
|
'description' => $data['description'], |
60
|
|
|
'group_egovernment_id' => $data['group_egovernment_id'], |
61
|
|
|
'sector_egovernment_id' => $data['sector_egovernment_id'], |
62
|
|
|
'link' => $data['link'], |
63
|
|
|
]); |
64
|
|
|
|
65
|
|
|
if($this->textInfo){ |
66
|
|
|
echo "============[DATA]============\n"; |
67
|
|
|
$this->orangeText('user_id : ').$this->greenText($data['user_id']); |
|
|
|
|
68
|
|
|
echo"\n"; |
69
|
|
|
$this->orangeText('label : ').$this->greenText($data['label']); |
|
|
|
|
70
|
|
|
echo"\n"; |
71
|
|
|
$this->orangeText('description : ').$this->greenText($data['description']); |
|
|
|
|
72
|
|
|
echo"\n"; |
73
|
|
|
$this->orangeText('group_egovernment_id : ').$this->greenText($data['group_egovernment_id']); |
|
|
|
|
74
|
|
|
echo"\n"; |
75
|
|
|
$this->orangeText('sector_egovernment_id : ').$this->greenText($data['sector_egovernment_id']); |
|
|
|
|
76
|
|
|
echo"\n"; |
77
|
|
|
$this->orangeText('link : ').$this->greenText($data['link']); |
|
|
|
|
78
|
|
|
echo"\n"; |
79
|
|
|
echo "============[DATA]============\n\n"; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$this->greenText('[ SEEDER DONE ]'); |
85
|
|
|
echo"\n\n"; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/* text color: orange */ |
89
|
|
|
protected function orangeText($text) |
90
|
|
|
{ |
91
|
|
|
printf($this->ORANGE.$text.$this->NC); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/* text color: green */ |
95
|
|
|
protected function greenText($text) |
96
|
|
|
{ |
97
|
|
|
printf($this->GRN.$text.$this->NC); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/* function read CSV file */ |
101
|
|
|
protected function readCSV() |
102
|
|
|
{ |
103
|
|
|
/* Silahkan di rubah sesuai struktur file csv */ |
104
|
|
|
$file = fopen(database_path("seeds/".$this->fileName), "r"); |
105
|
|
|
$all_data = array(); |
106
|
|
|
$row = 1; |
|
|
|
|
107
|
|
|
while(($data = fgetcsv($file, 1000, ",")) !== FALSE){ |
|
|
|
|
108
|
|
|
$all_data[] = ['user_id' => $data[0], |
109
|
|
|
'label' => $data[1], |
110
|
|
|
'description' => $data[2], |
111
|
|
|
'group_egovernment_id' => $data[3], |
112
|
|
|
'sector_egovernment_id' => $data[4], |
113
|
|
|
'link' => $data[5], |
114
|
|
|
]; |
115
|
|
|
} |
116
|
|
|
fclose($file); |
|
|
|
|
117
|
|
|
|
118
|
|
|
return $all_data; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.