File: D:/HostingSpaces/centrum8a/centrum8a.com/app/KommaApp/Kms/Core/Eav/Repository.php
<?php
namespace App\KommaApp\Kms\Core\Eav;
use Illuminate\Database\Eloquent\Model;
class Repository
{
/**
* Repository constructor.
*/
public function __construct()
{
}
public static function createTables(EntityInterface $entity, AttributeInterface $attribute, ValueInterface $value)
{
if(!is_a($entity, Model::class)) throw new \InvalidArgumentException("The entity model class must be a child instance of an eloquent model (Illuminate\Database\Eloquent\Model)");
if(!is_a($attribute, Model::class)) throw new \InvalidArgumentException("The attribute model class must be a child instance of an eloquent model (Illuminate\Database\Eloquent\Model)");
if(!is_a($value, Model::class)) throw new \InvalidArgumentException("The value model class must be a child instance of an eloquent model (Illuminate\Database\Eloquent\Model)");
\Schema::create($entity->getTable(), function ($table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
});
\Schema::create($attribute->getTable(), function ($table) {
$table->increments('id');
$table->integer('entity_id')->nullable();
$table->string('name');
$table->timestamps();
});
\Schema::create($value->getTable(), function ($table) {
$table->increments('id');
$table->integer('attribute_id')->nullable();
$table->integer('language_id')->nullable();
$table->string('name');
$table->timestamps();
});
}
/**
* Drops the tables as created with the createTables method.
*
* @see Repository::createTables()
* @return $this
*/
public static function dropTables(EntityInterface $entity, AttributeInterface $attribute, ValueInterface $value)
{
if(!is_a($entity, Model::class)) throw new \InvalidArgumentException("The entity model class must be a child instance of an eloquent model (Illuminate\Database\Eloquent\Model)");
if(!is_a($attribute, Model::class)) throw new \InvalidArgumentException("The attribute model class must be a child instance of an eloquent model (Illuminate\Database\Eloquent\Model)");
if(!is_a($value, Model::class)) throw new \InvalidArgumentException("The value model class must be a child instance of an eloquent model (Illuminate\Database\Eloquent\Model)");
\Schema::drop($entity->getTable());
\Schema::drop($attribute->getTable());
\Schema::drop($value->getTable());
}
}