1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
-
- class DatabaseSeeder extends Seeder {
-
-
-
- public function run()
- {
- Eloquent::unguard();
-
-
- $this->call('UserTableSSNDecrypter');
- $this->call('UserTableSeeder');
- $this->call('CourseTableSeeder');
- $this->call('UserTableSSNEncrypter');
- $this->call('StudentTableSeeder');
- $this->call('CourseStudentTableSeeder');
-
-
-
- }
-
-
-
- public function insertFromCSV($table, $filename)
- {
-
- DB::statement('SET FOREIGN_KEY_CHECKS=0;');
-
-
- DB::table($table)->truncate();
-
-
- DB::statement('SET FOREIGN_KEY_CHECKS=1;');
-
-
- $file = fopen('app/database/csv/'.$filename, 'r');
- $columns = fgetcsv($file, 5000, ",");
-
-
- $rowIndex = 0;
-
-
- $dbArray=array();
-
-
- while($data = fgetcsv($file, 5000, ","))
- {
-
- $columnIndex = 0;
-
-
- foreach($data as $value)
- {
- $dbArray[$rowIndex][$columns[$columnIndex]] = $value;
- $columnIndex++;
- }
- $rowIndex++;
- }
-
- DB::table($table)->insert($dbArray);
- }
- }
|