2017-12-10 11:21:49 +08:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Migration base class with some extra functionality
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Models\Migrations;
|
|
|
|
|
|
|
|
use DB;
|
|
|
|
use Illuminate\Database\Migrations\Migration as MigrationBase;
|
|
|
|
|
|
|
|
class Migration extends MigrationBase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Add rows to a table
|
|
|
|
* @param $table
|
|
|
|
* @param $rows
|
|
|
|
*/
|
|
|
|
public function addData($table, $rows)
|
|
|
|
{
|
|
|
|
foreach ($rows as $row) {
|
|
|
|
try {
|
|
|
|
DB::table($table)->insert($row);
|
|
|
|
} catch (Exception $e) {
|
2017-12-10 11:56:26 +08:00
|
|
|
# setting already exists, just ignore it
|
2017-12-10 11:21:49 +08:00
|
|
|
if ($e->getCode() === 23000) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|