osb/database/migrations/2017_12_06_000000_CreateTableCurrencies.php
Deon George 33658e37a3
WIP: Standard backend theme page and login
Signed-off-by: Deon George <deon@leenooks.net>
2017-12-12 16:28:49 +11:00

50 lines
1006 B
PHP

<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use App\Models\Currency;
class CreateTableCurrencies extends Migration
{
private $convert = 'App\Models\Old\Currency';
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::dropIfExists('currencies');
Schema::create('currencies', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('symbol',2)->nullable();
$table->string('threecode',3);
$table->boolean('active');
});
if ($this->convert)
foreach (($this->convert)::all() as $o)
{
$oo = new Currency;
$oo->name = $o->name;
$oo->symbol = $o->symbol;
$oo->threecode = $o->three_digit;
$oo->active = $o->three_code == 'AUS' ? TRUE : FALSE;
$oo->save();
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('currencies');
}
}