Rename Interfaces to Contracts to better match Laravel conventions
This commit is contained in:
45
app/Contracts/Migration.php
Normal file
45
app/Contracts/Migration.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Contracts;
|
||||
|
||||
use DB;
|
||||
|
||||
/**
|
||||
* Class Migration
|
||||
*/
|
||||
abstract class Migration extends \Illuminate\Database\Migrations\Migration
|
||||
{
|
||||
/**
|
||||
* At a minimum, this function needs to be implemented
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function up();
|
||||
|
||||
/**
|
||||
* A method to reverse a migration doesn't need to be made
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
// setting already exists, just ignore it
|
||||
if ($e->getCode() === 23000) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user