58 lines
1.3 KiB
PHP
58 lines
1.3 KiB
PHP
<?php
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Database\Migrations\Migration;
|
|
|
|
class AddModelToProduct extends Migration
|
|
{
|
|
/**
|
|
* Run the migrations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function up()
|
|
{
|
|
Schema::table('ab_product', function (Blueprint $table) {
|
|
$table->string('model')->nullable();
|
|
});
|
|
|
|
// Go through our services and add the relation
|
|
foreach (\App\Models\Product\Adsl::all() as $o)
|
|
$this->update($o,'ADSL');
|
|
/*
|
|
foreach (\App\Models\Product\Domain::all() as $o)
|
|
$this->update($o);
|
|
foreach (\App\Models\Product\Host::all() as $o)
|
|
$this->update($o);
|
|
*/
|
|
foreach (\App\Models\Product\SSL::all() as $o)
|
|
$this->update($o,'SSL');
|
|
/*
|
|
foreach (\App\Models\Product\Voip::all() as $o)
|
|
$this->update($o);
|
|
*/
|
|
}
|
|
|
|
/**
|
|
* Reverse the migrations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function down()
|
|
{
|
|
Schema::table('ab_product', function (Blueprint $table) {
|
|
$table->dropColumn('model');
|
|
});
|
|
}
|
|
|
|
function update(\Illuminate\Database\Eloquent\Model $o,$file)
|
|
{
|
|
foreach (\App\Models\Product::where('prod_plugin_file',$file)->where('prod_plugin_data',$o->id)->get() as $oo)
|
|
{
|
|
$oo->model = get_class($o);
|
|
$oo->save();
|
|
}
|
|
}
|
|
}
|