полиморфные отношения «многие ко многим»
Мне нужно создать полиморфные отношения между Entity2, Entity1 и Types. связь между событием и типами легко сделать, но у вас есть проблема в отношениях между сущностью 2 и типами, потому что это отношение многие ко многим.
class CreateTypesTable extends Migration {
public function up()
{
Schema::create('types', function(Blueprint $table) {
$table->increments('id');
$table->integer('typeable_id');
$table->string('typeable_type', 20);
$table->string('name', 20);
$table->text('description')->nullable();
});
}
}
class Entity1 extends Eloquent {
public function type()
{
return $this->morphMany('App\Models\Type', 'typeable');
}
}
class Type extends Eloquent {
public function typeable()
{
return $this->morphTo();
}
}
так как отношения между типами и сущностями2 много для многих, не знаю, как их создать, потому что для этого нужна сводная таблица.
class Entity2 extends Eloquent {
public function types()
{
// return $this->morphMany('App\Models\Type', 'typeable');
}
}