Add Generic service - all services should have a type model

This commit is contained in:
Deon George 2020-12-02 21:36:36 +11:00
parent 4718bf3057
commit 20ddacd9a3
3 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,9 @@
<?php
namespace App\Models\Product;
use App\Models\Base\ProductType;
class Generic extends ProductType
{
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Models\Service;
use App\Models\Base\ServiceType;
class Generic extends ServiceType
{
protected $table = 'service__generic';
public $timestamps = FALSE;
}

View File

@ -0,0 +1,58 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddServiceGeneric extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('service__generic', function (Blueprint $table) {
$table->bigInteger('id',TRUE);
$table->integer('site_id');
$table->bigInteger('service_id');
$table->bigInteger('product_id');
$table->foreign('site_id')->references('id')->on('ab_setup');
$table->foreign(['service_id','site_id'])->references(['id','site_id'])->on('ab_service');
$table->foreign(['product_id','site_id'])->references(['id','site_id'])->on('ab_product');
$table->unique(['site_id','service_id']);
});
foreach (\App\Models\Service::whereNULL('model')->get() as $o) {
$oo = new \App\Models\Service\Generic;
$oo->service_id = $o->id;
$oo->site_id = $o->site_id;
$oo->product_id = 0;
$oo->save();
$o->model = 'App\Models\Service\Generic';
$o->save();
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
foreach (\App\Models\Service::where('model','App\Models\Service\Generic')->get() as $o) {
if ($o->type)
$o->type->delete();
$o->model = NULL;
$o->save();
}
Schema::dropIfExists('service__generic');
}
}