This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
site-base/database/migrations/2017_12_06_000001_CreateTableCountries.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

60 lines
1.3 KiB
PHP

<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use App\Models\{Country,Currency};
class CreateTableCountries extends Migration
{
private $convert = 'App\Models\Old\Country';
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::dropIfExists('countries');
Schema::create('countries', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('twocode',2)->nullable();
$table->string('threecode',3);
$table->integer('currency_id')->unsigned()->nullable();
$table->boolean('active');
$table->foreign('currency_id')->references('id')->on('currencies');
});
if ($this->convert)
foreach (($this->convert)::all() as $o)
{
if ($o->currency)
$co = Currency::where('name',$o->currency->name)->firstOrFail();
$oo = new Country;
$oo->name = $o->name;
$oo->twocode = $o->two_code;
$oo->threecode = $o->three_code;
$oo->active = $o->three_code == 'AUS' ? TRUE : FALSE;
if ($o->currency)
$co->countries()->save($oo);
else
$oo->save();
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('countries');
}
}